Hello, I tried cloning this repo: https://github.com/mongodb/template-app-react-native-todo (downloaded it as a zip file, uncompressed it and then changed the app id in the atlasConfig.json to match what I have for my example app under app services in MongoDB atlas). I also did a realm-cli login with a private and public API key in the root directory of the project. However, when I try writing data to a schema I want to create called Links, I get the following error:
This is the error in my js server:
LOG Running "SyncTutorial" with {"rootTag":1}
ERROR Error: Exception in HostFunction: Cannot write to class Link when no flexible sync subscription has been created., js engine: hermes
Error: ENOENT: no such file or directory, open 'C:\Users\matth\Documents\ReactNativeAppDevelopment\TeeScanVersionFour\template-app-react-native-todo-main\JavaScript'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at getCodeFrame (C:\Users\matth\Documents\ReactNativeAppDevelopment\TeeScanVersionFour\template-app-react-native-todo-main\node_modules\metro\src\Server.js:1047:18)
at Server._symbolicate (C:\Users\matth\Documents\ReactNativeAppDevelopment\TeeScanVersionFour\template-app-react-native-todo-main\node_modules\metro\src\Server.js:1133:22)
at async Server._processRequest (C:\Users\matth\Documents\ReactNativeAppDevelopment\TeeScanVersionFour\template-app-react-native-todo-main\node_modules\metro\src\Server.js:468:7) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: 'C:\\Users\\matth\\Documents\\ReactNativeAppDevelopment\\TeeScanVersionFour\\template-app-react-native-todo-main\\JavaScript'
}
Error: ENOENT: no such file or directory, open 'C:\Users\matth\Documents\ReactNativeAppDevelopment\TeeScanVersionFour\template-app-react-native-todo-main\http:\10.0.2.2:8081\index.bundle?platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at getCodeFrame (C:\Users\matth\Documents\ReactNativeAppDevelopment\TeeScanVersionFour\template-app-react-native-todo-main\node_modules\metro\src\Server.js:1047:18)
at Server._symbolicate (C:\Users\matth\Documents\ReactNativeAppDevelopment\TeeScanVersionFour\template-app-react-native-todo-main\node_modules\metro\src\Server.js:1133:22)
at async Server._processRequest (C:\Users\matth\Documents\ReactNativeAppDevelopment\TeeScanVersionFour\template-app-react-native-todo-main\node_modules\metro\src\Server.js:468:7) {
errno: -4058,
syscall: 'open',
code: 'ENOENT',
path: 'C:\\Users\\matth\\Documents\\ReactNativeAppDevelopment\\TeeScanVersionFour\\template-app-react-native-todo-main\\http:\\10.0.2.2:8081\\index.bundle?platform=android&dev=true&minify=false&app=com.synctutorial&modulesOnly=false&runModule=true'
}
Essentially, the only things I added to the code after downloading the repo and running it are a file titled LinkSchema.tsx that looks like so:
import { BSON } from 'realm';
export class Link extends Realm.Object<Link> {
_id!: BSON.ObjectId;
user!: string;
LinkID!: string;
originalURL!: string;
static schema: Realm.ObjectSchema = {
name: 'Link',
primaryKey: '_id',
properties: {
_id: {type: 'objectId', default: () => new BSON.ObjectId()},
user: { type: 'string', default: 'matthew.g.2219@gmail.com' },
LinkID: { type: 'string', default: 'lnk_3dhs_9dCPkpOgUmB' },
originalURL: 'string',
},
};
}
I also changed my RealmContext.ts file to look like so:
import {createRealmContext} from '@realm/react';
import {Item} from './ItemSchema';
import {Link} from './LinkSchema';
export const realmContext = createRealmContext({
schema: [Item, Link],
});
And in my itemlistview.tsx file, I changed the createItem function to write to my Link schema (I remembered to do an import link from linkschema.tsx at the top of my file). You can see the original function (that works by the way and writes to my cluster: todo->item in MongoDB atlas) that I commented out and the function I wrote that’s not commented out:
// createItem() takes in a summary and then creates an Item object with that summary
// const createItem = useCallback(
// ({summary}: {summary: string}) => {
// // if the realm exists, create an Item
// realm.write(() => {
// return new Item(realm, {
// summary,
// owner_id: user?.id,
// });
// });
// },
// [realm, user],
// );
const createItem = useCallback(
({summary}: {summary: string}) => {
// if the realm exists, create an Item
realm.write(() => {
return new Link(realm, {
user: 'mgkid12321@gmail.com',
LinkID: 'lnklnk',
originalURL: 'youtube.com',
});
});
},
[realm, user],
);
Even after turning developer mode on, I still can’t write to the Links schema. I also tried setting my devices sync to flexible via my app services UI but that didn’t change anything.
I uploaded the repo of the project I’m currently working on to Github so that you can easily navigate my code and tell me where I can modify it to fix this issue: GitHub - MatthewGerges/TeeScan: A react native app that uses Realm Sync to connect to MongoDB
To get realm SDK to work, I also tried downloading the app services zip file from the app services UI but the Zip folder had nothing in it. I also tried using the realm cli to create a template app with a given app id but after creating the app and doing a pull and push command, it gave me the error group not found.