React native realm mongodb query and offline usage

449 Views Asked by At

We have a use case where logged in user will has list of products which can be shown even if not internet connection and i tried to achieve this using realm device sync (Flexible) using mongodb query (Aggregation) but it able to fetch products only when internet is available so my question is that is it possible with realm device sync that we sync products from mongodb using mongodb query and load even if there is no internet connection?

Below is sample code that i tried to integrate in our app but it

const config = {
    id: this.id
};
this.app = new Realm.App(config);

const credentials = Realm.Credentials.anonymous();
await this.app.logIn(credentials);


this.connection =  await Realm.open({
    schema: [Customer],
    sync: {
        user: this.app.currentUser,
        flexible: true,
        onError: (_session, error: any) => {
            console.log('sync error');
            console.log(error.name, error.message);
        }
    }
});

const mongodb = this.app.currentUser.mongoClient('mongodb-atlas');
const collectionUsers = mongodb.db('dev_database').collection('user_roles');

const pipeline = [{
    ...
}];

const result = await collectionUsers.aggregate(pipeline);
// Get result when user is online but do not loads after i switch to offline

So problem is above aggregate query doesn't work if user is offline

I tried realm mongodb query and expecting it should work when user is offline as well

0

There are 0 best solutions below