Answers for "MongoError: MongoClient must be connected before calling MongoClient.prototype.db"

0

MongoError: MongoClient must be connected before calling MongoClient.prototype.db

var MongoClient = require('mongodb').MongoClient;

MongoClient.connect("mongodb://localhost:50000,localhost:50001/integration_test_?w=0&readPreference=secondary", function(err, db) {
  test.equal(null, err);
  test.ok(db != null);

  db.collection("replicaset_mongo_client_collection").update({a:1}, {b:1}, {upsert:true}, function(err, result) {
    test.equal(null, err);
    test.equal(1, result);

    db.close();
    test.done();
  });
});
Posted by: Guest on December-21-2020
0

MongoError: MongoClient must be connected before calling MongoClient.prototype.db

var MongoClient = require('mongodb').MongoClient;

MongoClient.connect("mongodb://localhost:30000,localhost:30001/integration_test_?w=0&readPreference=secondary", function(err, db) {
  test.equal(null, err);
  test.ok(db != null);

  db.collection("replicaset_mongo_client_collection").update({a:1}, {b:1}, {upsert:true}, function(err, result) {
    test.equal(null, err);
    test.equal(1, result);

    db.close();
    test.done();
  });
});
Posted by: Guest on December-21-2020

Code answers related to "MongoError: MongoClient must be connected before calling MongoClient.prototype.db"

Code answers related to "Javascript"

Browse Popular Code Answers by Language