-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
collection.watch() fails on React Native SDK #3494
Comments
The watch implementation for React Native is unfortunately not stable. The reason is fetch implementation doesn't implement the entire spec (see facebook/react-native#27741). If possible, using sync might be better. |
That is indeed unfortunate. Thank you for answering though, I'll start reading through the sync docs. Have a nice day! |
I'll reopen this issue as a reminder for us to improve this. It might be as easy as applying the @react-native-community/fetch polyfill (via react-native-polyfill-globals). |
Whats the estimate with the new polyfills implementation from RN? |
My best estimate is one week. The actual implementation will not take long, but we will have to add some more testing to verify that it works as we expect. |
Hi @kneth, Is there any update regarding this? |
After investigating the issue, we realized that it is required to enable the Babel plugin |
This was the source-code for the app we used to debug this: import {useEffect} from 'react';
import Realm from 'realm';
import 'react-native-polyfill-globals/auto';
const app = Realm.App.getApp('realmjstestapp-jjhtf');
async function getUser() {
await app.currentUser.logOut();
if (app.currentUser) {
return app.currentUser;
} else {
const credentials = Realm.Credentials.anonymous();
return app.logIn(credentials);
}
}
async function start() {
const user = await getUser();
console.log(user.id);
const runs = user
.mongoClient('mongodb-atlas')
.db('watch-test-db')
.collection('runs');
console.log('Starting to watch!');
for await (const run of runs.watch({})) {
console.log('An event came in:', run);
}
console.log('Done watching!');
}
const App = () => {
useEffect(() => {
start().catch(console.error);
}, []);
return null;
};
export default App; The observed behaviour is that the "Starting to watch!" message gets printed to the console but no event fires when changes happen to the documents on the server. Further investigations showed that the promise returned from the |
@kraenhansen still facing this issue despite installing the polyfills and the babel plugin, the generator throws an error saying its not iterable |
Still facing this issue after following all required steps. |
Did you add the two required poly fills?
|
Working now after a small tweak but not returning any change on document insert. Throwing abort error after 2-3 minutes. |
@SipNWork can I get you to create another issue with the exact version of Realm JS you're using and ideally a small reproduction showing off the issue? If you have time it would also be great to hear if upgrading to Realm JS v12 (soon to be released as |
Created a new issue for above |
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
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:And watchMessageCollection():
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
The text was updated successfully, but these errors were encountered: