Being new to MongoDB realm, try to use the MongoDB realm demo Task app (@realm/expo-template-js and @realm/expo-template-ts template).
I did not change anything apart from using realm version “11.0.0” instead of “^11.3.1” because of this problem.
But when I add a task I get the following error for both templates :
Android Bundling complete 58ms
ERROR Error: Exception in HostFunction: Property must be of type ‘object_id’, got (function _default() {
return new Realm.BSON.ObjectId();
})
Please find below Task.js of the JavaScript template (again, I did not change anything)
// This JS version of the Task model shows how to create Realm objects by
// defining a schema on the class, which is required if your project does not
// use TypeScript. If you are using TypeScript, we recommend using
// `@realm/babel-plugin` (https://github.com/realm/realm-js/blob/master/packages/babel-plugin/),
// which allows you to define your models using TypeScript syntax.
//
// See `Task.ts` in the Realm example app for an example of using the plugin.
export class Task extends Realm.Object {
constructor(realm, description, userId) {
super(realm, { description, userId: userId || "_SYNC_DISABLED_" });
}
// To use a class as a Realm object type in JS, define the object schema on the static property "schema".
static schema = {
name: "Task",
primaryKey: "_id",
properties: {
_id: { type: "objectId", default: () => new Realm.BSON.ObjectId() },
description: "string",
isComplete: { type: "bool", default: false },
createdAt: { type: "date", default: () => new Date() },
userId: "string",
},
};
}
Please find below Task.ts of the TypeScript template :
// This TS version of the Task model shows how to create Realm objects using
// TypeScript syntax, using `@realm/babel-plugin`
// (https://github.com/realm/realm-js/blob/master/packages/babel-plugin/).
//
// If you are not using TypeScript and `@realm/babel-plugin`, you instead need
// to defining a schema on the class - see `Task.js` in the Realm example app
// for an example of this.
import {Realm} from '@realm/react';
export class Task extends Realm.Object<Task> {
_id: Realm.BSON.ObjectId = new Realm.BSON.ObjectId();
description!: string;
isComplete: boolean = false;
createdAt: Date = new Date();
userId!: string;
static primaryKey = '_id';
constructor(realm: Realm, description: string, userId?: string) {
super(realm, {description, userId: userId || '_SYNC_DISABLED_'});
}
}