When reading objects, the ObjectId type is not an instance of ObjectId.
When reading an object with object ids, the property should be an instance of ObjectID
The property is in the following format:
["$oid", "603f6df28095c5cd1410d0f8"]
(an array of strings)
Given the following schema:
static schema: Realm.ObjectSchema = {
name: 'User',
primaryKey: '_id',
properties: {
_id: 'objectId',
name: 'string',
}
};
Creating an user like this:
realm?.write(() => {
realm.create(
User.schema.name,
{
_id: new ObjectId(),
name: "Test user",
}
);
});
When reading the users like this:
realm.objects<User>(User.schema.name)
The "_id" property isn't a ObjectId, but an array of strings.
See above
Please note: This only happens when debugging on chrome. Without a debugger, everything is working as expected.
Thanks for the detailed bug-report, we'll have to investigate further.
Is there any planned date for the fix to be made? It blocks debugging React Native apps if you use ObjectIds from Realm.
For example, we use in our code .toHexString() which fails when the objectid is a 2 element array.
We have a workaround, however it seems quite important for developing RN apps with Realm.
If you are debugging on iOS, you can use Safari Dev Tools to connect to your device's JS engine.
Most helpful comment
If you are debugging on iOS, you can use Safari Dev Tools to connect to your device's JS engine.