TypeError: app.currentUser.mongoClient is not a function

const appId = 'myAppId';
        const appConfig = {
          id: appId,
          timeout: 100000,
        };
const app = new Realm.App(appConfig);
const mongodb = app.currentUser.mongoClient("mongodb-atlas");

when i’m using above code in react native getting error “TypeError: app.currentUser.mongoClient is not a function”

Same Issue:
on going through dov i found “To access a collection, create MongoDB service handle for the user that you wish to access the collection with:”

there is some meaning in "MongoDB service handle for the users, which i am unable to understand.

HELP

Hi @Ayushi_Mishra,

Welcome to the community!

From the code snippet you have provided, it does not look like you have authenticated the app session. The currentUser attribute for your app will be null as you have not called app.logIn(<Credentials>). In order to have access to the mongoClient function, all that needs to be done is to login against one of our included authentication providers like below

const appId = 'myAppId';
const appConfig = {
  id: appId,
  timeout: 100000,
};
const app = new Realm.App(appConfig);

// Session authentication using the anonymous user
const credentials = Realm.Credentials.anonymous();
await app.logIn(credentials);

const mongodb = app.currentUser.mongoClient("mongodb-atlas");

As a note, our tutorial is extremely helpful in showing how to build a simple tracker app using React Native.

I hope this solves your problem.

Cheers,
Giuliano