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

Opret forbindelse til MongoDB Atlas Cluster db med react-native app

Jeg synes, du skal omskrive koden efter formatet foreslået af mongodb her:

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

Så i bund og grund:

    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.

       }
    });


  1. Hvordan man reaktivt aggregerer mongodb i meteor

  2. Brug af MongoDB som datakilde i GoLang

  3. Få indeks for givet element i matrixfelt i MongoDB

  4. Hvordan forespørger man direkte indlejret felt uden at angive overordnet felt?