var MongoClient = require('mongodb').MongoClient,
assert = require('assert');
MongoClient.connect('mongodb://x.x.x:27017,x.x.x.x:27017/xx?replicaSet=xxx&wtimeoutMS=2000', function(err, db) {
// Create a collection we want to drop later
var collection = db.collection('test');
// Insert a bunch of documents for the testing
collection.find().toArray(function(err, docs) {
assert.equal(null, err);
// test.equal(3, docs.length);
console.log(docs);
db.close();
});
});
the error info :
TypeError: Cannot read property 'collection' of null
at /Users/shanyy/LearningFiles/learnmongodb/test.js:7:22
at connectCallback (/x/node_modules/mongodb/lib/mongo_client.js:315:5)
at /x/node_modules/mongodb/lib/mongo_client.js:222:11
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)