3

When I'm calling:

const user = await app.logIn(creds);
const mongodb = user.mongoClient("mongodb-atlas");

from react-native in an attempt to connect to MongoDB Atlas (app is an instance of a Realm App) I'm getting the following error:

TypeError: user.mongoClient is not a function

The user is not null and I can call user.logOut successfully. I'm not sure where to from here. Any ideas?

Thanks in advance!

Jay
  • 34,438
  • 18
  • 52
  • 81
  • The error is pretty clear; `mongoClient` is not a user object function. Take a look look at the Getting Started Guide[Auth Users](https://docs.mongodb.com/realm/sdk/react-native/examples/authenticate-users/#std-label-react-native-authenticate-users) and then [Open A Realm](https://docs.mongodb.com/realm/sdk/react-native/quick-start/#open-a-realm). The next step is to create a config as shown [sync](https://docs.mongodb.com/realm/sdk/react-native/examples/sync-changes-between-devices/#pause-or-resume-a-sync-session) to which you can then connect to realm `let realm = await Realm.open(config)` – Jay May 01 '21 at 13:03
  • @Jay In the docs here, it seems to be including mongoClient: https://docs.mongodb.com/realm/sdk/react-native/examples/query-mongodb/#connect-to-a-linked-cluster The reason I'm not using sync is that this collection is not very correlated with user data so using a partition on it doesn't make sense (sync requires a partition key). Is that correct reasoning? Or should I sync all collections? – Matthew Yang May 01 '21 at 21:29
  • It is! Did you try app.currentUser.mongoClient(? Also, to clarify using a partition on it - A Realm is a partition and a partition is a Realm - they are the same thing. The documentation is a bit unclear on that point and it uses the two terms interchangeably e.g. when a partitionKey is added to a document, that key defines the Realm the object is part of. And yes, sync requires a partition key; if the data will never be sync'd then it doesn't need a key. – Jay May 02 '21 at 13:52
  • @Jay Thanks for the clarification! I have tried app.currentUser.mongoClient, but it gave the same error. I thought back to the design of my project, and thought that I should instead have a server rather than serverless (which is what I'm doing right now) because I don't want to be too reliant on MongoDB. This also means that I don't have to deal with this problem anymore! Thanks for all the help! – Matthew Yang May 02 '21 at 20:15

1 Answers1

1

A bit late but for those coming here with the same problem, see my stackoverflow question here and the opened issue in realm-js github.

user.callFunction() and user.mongoClient() are unavailable while debugging using Chrome.

They are not going to fix this because they are working on Hermes engine and Flipper debugging instead.

XplosiVe06
  • 568
  • 3
  • 23