MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Connettiti a MongoDB Atlas Cluster db con l'app nativa di reazione

Penso che dovresti riscrivere il codice seguendo il formato suggerito da mongodb qui:

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

Quindi essenzialmente:

    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.

       }
    });