Connect to MongoDB Atlas Cluster db with react-native app Connect to MongoDB Atlas Cluster db with react-native app mongoose mongoose

Connect to MongoDB Atlas Cluster db with react-native app


I think you should rewrite the code following the format suggested by mongodb here:

https://mongodb.github.io/node-mongodb-native/api-articles/nodekoarticle1.html

So essentially:

    const MongoClient = require('mongodb').MongoClient;    //make sure to check connection string is correct here, since this depends on the whether you are running standalone, replica, sharded cluster     const uri = "mongodb+srv://<userName>:<password>@testcluster1-dbdq3.mongodb.net/test?retryWrites=true&w=majority";    MongoClient.connect(uri, { useNewUrlParser: true }, function(err, client) {       if (err) {             //error       } else {             var collection = client.db('test').collection('devices');             //client.close() should be called after you are done performing actions such as collection.update, etc.       }    });


you can use any npm package with Expo if it works with RN (React Native), but you may need to detach in order to do so. Any npm packages which include native iOS or Android code will not work with Expo out of the box, unfortunately. Because MongoDB NPM package just mentioned the Node.js in thier docs, this doesn't mean that it will work on React Native. That's why MongoDB made this page about JUST React Native https://docs.mongodb.com/realm/tutorial/react-native/

You may need to use Realm Package to connect to MongoDB with React Native.