Search code examples
javascriptreact-nativerealm

Is it possible to create a realm db without a cloud instance?


All of the documentation that Ive seen for realm, specifically for react native, wants me to use a sync'd realm that is hosted on their cloud platform. The information is "stored locally" but is there any way to set this up without using their cloud service?


Solution

  • Don't pass "sync" property to the configuration, you can see all available props here

    const dbRealmConfig = {
      schema: [model1, model2]  
    }
    
    const localRealm = await Realm.open(dbRealmConfig);
    // or if you need synchronously -> new Realm(dbRealmConfig);
    
    // do whatever you want with the realm
    const [grabSomeObject] = localRealm.objects('model1').filtered(`SomeModelProp = "${someVariable}"`);
    localRealm.write(() => {
      someVariable.SomeModelProp = 'abc';
    ...
    });
    

    You should go through the Realm docs Jay linked (Realm React Getting Started Guide), it's pretty well explained.