The problem
I’m new to MongoDB realm. And to learn more about the product i followed the React Native with javascript tutorial. After doing so, i started to sandbox the library by testing the anonymous( ) log in. But unfortunately every time the code tries to open the tutorial realm, this error happens:
Error opening realm: {
\"line\": 102194,
\"column\": 47,
\"sourceURL\": \"http://localhost:8081/index.bundle?platform=android&dev=true&minify=false\"
}
The troubleshooting
Looking up the line 102194 was the first attempt, and this is it’s content:
var behavior = realmConstructor.exists(config) ? "existingRealmFileBehavior" : "newRealmFileBehavior";
The second attempt was looking at the open( ) documentation. As far as i could see nothing is missed in the code.
The set up
Node js v15.2.1
React Native v0.63.3
MongoDB Realm v4.4 (same as tutorial)
The code
import Realm from 'realm';
let app;
const getRealm = getRealmApp();
async function openRealm(gotUser) {
try {
let userKey = '5fc2945329e5d0fc6d53f5bb';
const config = {
sync: {
gotUser,
partitionValue: `user=${userKey}`,
},
};
Realm.open(config).then((userRealm) => {
const dataUser = userRealm;
const gotData = dataUser.objects("User");
console.log(`The realm objects are: ${gotData}`);
});
} catch (error) {
throw `Error opening realm: ${JSON.stringify(error, null, 2)}`;
}
}
function getRealmApp() {
if (app === undefined) {
const appId = 'tasktracker-wqoyx';
const appConfig = {
id: appId,
timeout: 10000,
};
app = new Realm.App(appConfig);
}
return app;
};
async function logInAsync() {
try {
const creds = Realm.Credentials.anonymous();
const newUser = await getRealm.logIn(creds);
console.log('user authenticated!', newUser.isLoggedIn);
openRealm(newUser);
} catch (error) {
console.log(`Unable to log in because: ${error}`)
}
}
export const onPressSignIn = async () => {
try {
await logInAsync();
} catch (error) {
Alert.alert(`Failed to log in: ${error.message}`);
}
}
Any help is appreciated. Thanks in advance!