0

Is there a way to create a collection in MongoDB stitch app in react-native. I tried the normal MongoDB way

const stitchClient = Stitch.getAppClient(myAppID);
const mongodb = stitchClient.getServiceClient(RemoteMongoClient.factory, "mongodb-atlas")
    .db("ToDo");
        // console.log("mongodb is ", mongodb);
mongodb.createCollection("test", (err, res) => {
   if (err) {
       throw ("Error creating a collection : ", err);
   }
   console.log("Collection creted");
});

But then react-native keeps giving this error :

TypeError: undefined is not a function(near 'MongoDB.createCollection...')

calebdeji
  • 11
  • 4

1 Answers1

0

But then react-native keeps giving this error

RemoteMongoDatabase does not have createCollection method. It's not a function that you could call/invoke.

Conceptually, worth mentioning that MongoDB Stitch prevents access to your data by default. First you need to create a collection first, and define it's Rules. You can create a collection either manually from mongo shell or from Stitch Rules UI. Please note that you must define at least one role before you can successfully query a collection.

See also Stitch: Define Roles And Permissions for step by step procedure on how to create Rules.

Wan B.
  • 18,367
  • 4
  • 54
  • 71