Realm-js: ObjectID Inconsistency on read

Created on 3 Mar 2021  路  4Comments  路  Source: realm/realm-js

Goals

When reading objects, the ObjectId type is not an instance of ObjectId.

Expected Results

When reading an object with object ids, the property should be an instance of ObjectID

Actual Results

The property is in the following format:
["$oid", "603f6df28095c5cd1410d0f8"]

(an array of strings)

Steps to Reproduce

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.

Code Sample

See above

Version of Realm and Tooling

  • Realm JS SDK Version: 10.2.0
  • Node or React Native: React Native
  • Client OS & Version: React native 0.63.4
  • Which debugger for React Native: Chrome
O-Community T-Bug

Most helpful comment

If you are debugging on iOS, you can use Safari Dev Tools to connect to your device's JS engine.

All 4 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

kevinnguy picture kevinnguy  路  3Comments

emrehayirci picture emrehayirci  路  3Comments

matt2legit picture matt2legit  路  3Comments

jmartindivmedianet picture jmartindivmedianet  路  3Comments

max-zu picture max-zu  路  3Comments