-
Type: Improvement
-
Resolution: Fixed
-
Priority: Critical - P2
-
None
-
Affects Version/s: None
-
Component/s: None
Goals
I'm trying to monitor collection changes on a remote MongoDB Atlas database.
Expected Results
I followed the example on the official Realm docs to use the collection.watch() functionality for the RN SDK. The example works with Node, and it returns any newly inserted objects in the collection, which is what I'm going for. The exact same code, however, does not work in my RN project.
Actual Results
I get the following error message
EROR [TypeError: Invalid attempt to iterate non-iterable instance. In order to be iterable, non-array objects must have a [Symbol.iterator]() method.]
<!--- e.g. the stack trace of a crash -->
Steps to Reproduce
The error can be reproduced running the following code with the specified SDK and RN versions at the bottom. I call this function inside the componentDidMount() function, which looks like this:
componentDidMount() { this.watchMessageCollection().catch((err) => console.log('ERROR', err)); }
And watchMessageCollection():
async watchMessageCollection() { const {user} = this.props.session; const db = user.mongoClient('mongodb-atlas').db('main'); const messages_collection = db.collection('chat_messages'); const generator = messages_collection.watch(); for await (const change of generator) { const {documentKey, fullDocument} = change; console.log(`new document: ${documentKey}`, fullDocument); } }
I tried running this function on different project files with the same result, so there's something about the generator itself that's off. The user auth works on my RN project, as do the database and collection connections.
Version of Realm and Tooling
- Realm JS SDK Version: 10.1.2
- Node: v15.1.0
- React Native: 0.63.4
- OS: Ubuntu 20.04.1 LTS
- is related to
-
RJS-1144 Watch stream reports change after being cancelled
- Backlog
- links to