Realm-js: [react-native][Android] Existing realm opening issue

Created on 22 Apr 2018  ยท  4Comments  ยท  Source: realm/realm-js

Hello !

Goals

I've a pre-bundeld realm (generated with a home-made Node script) that I want to open in my android app using react-native.

Expected Results

Being able to access the data stored in the bundle from react-native. (It's working fine when opening the Realm with Node.)

Actual Results

Red screen error : Unable to open a realm at path ./realm/default.realm.management. Please use a path where your app has read-write permissions.

But it exists, I even created the "default.realm.management" dir, and put chmod 777 to all of this...

File architecture :

.
โ”œโ”€โ”€ ScreenCallingRealm.js
โ”œโ”€โ”€ realm
โ”‚ย ย  โ”œโ”€โ”€ default.realm
โ”‚ย ย  โ”œโ”€โ”€ default.realm.lock
โ”‚ย ย  โ””โ”€โ”€ default.realm.management

Maybe the Realm path is not relative to the script calling it ? (but would be strange)

Code Sample

    Realm.open({
      path: './realm/default.realm',
      schema: [some, schemas],
    }).then((realm) => {
      alert(JSON.stringify(realm.objects('Dog').length));
    });
  }

Version of Realm and Tooling

  • Realm JS version 2.2.20 (Node & react-native)
  • Node or React Native: Generated with Node v8.10.0, used with react-native 0.54.4
  • Client OS & Version: Android 6.0
  • Which debugger for React Native: None
O-Community T-Help

Most helpful comment

Awesome, it's working !

If it can help, for android :

  • copy bundle (.realm) to android/app/src/main/assets
  • simply call :
    Realm.copyBundledRealmFiles(); Realm.open({ schema: realmConfig.realmSchemas, path: 'the name of your realm file', }).then((realm) => { // do stuff });

All 4 comments

First, you should only include default.realm. Both .lock and .management are aux. files/directories.

You can use Realm.copyBundledRealmFiles(). I just realized that we forgot to document it :smile:. You can see an example in our tests of it: https://github.com/realm/realm-js/blob/master/tests/js/realm-tests.js#L883

Thanks ! :)

I'll tro to use this feature in a few days then.

@nathan-K- I close the issue for now but don't hesitate to reopen if you experience any issues.

Awesome, it's working !

If it can help, for android :

  • copy bundle (.realm) to android/app/src/main/assets
  • simply call :
    Realm.copyBundledRealmFiles(); Realm.open({ schema: realmConfig.realmSchemas, path: 'the name of your realm file', }).then((realm) => { // do stuff });
Was this page helpful?
0 / 5 - 0 ratings