'watch' is not a function

I’m trying to use ‘watch()’ from withing a realm function so it can respond immediately to changes in the database. This is my code now:

  const cluster = context.services.get('mongodb-atlas');
  db = cluster.db("db");
  const demoCollection = db.collection("demo");
  watchCursor = demoCollection.watch();

and it raises the error: “‘watch’ is not a function”, so I assume I haven’t used it correctly.
What is the correct syntax for this? can I see an example?

Hi @Tal_Ben-zvi – We don’t currently support using watch() within Realm Functions. For this use cases we would suggest setting up a Trigger to react to changes. https://docs.mongodb.com/realm/triggers/database-triggers/

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.