Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-727

When no primary, createCollection fails to return with an error

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 2.2.0
    • Affects Version/s: None
    • Component/s: MongoDB 3.2
    • Labels:
      None

      When you have a 3 node replica set with 2 nodes down and connectWithNoPrimary:true, when calling db.createCollection it does not throw an error and just hangs there.

      Nodejs Driver: 2.1.17
      MongoDB: 3.2.6 and 3.0.11

      Here is some sample code to test.

      var MongoClient = require('mongodb').MongoClient
          , format = require('util').format;
      MongoClient.connect('mongodb://127.0.0.1:27030,127.0.0.1:27031,127.0.0.1:27032/beagles', 
      	{
      	  replSet: {
      	    connectWithNoPrimary:true,
      	    replicaSet: 'beagles',
      	    readPreference: 'primaryPreferred'
      	  }
      	}, 
      	function (err, db) {
      	    if (err) {
      	        throw err;
      	    } else {
      	        console.log("successfully connected to the database");	        
      	    }
      
      	    var collection = db.collection('dogs');
      
      	    try {
      		    console.log("before insert");
      		    db.createCollection("cats", {w: 1, wtimeout: 1000}, function(err, collection) {
      		    	console.log(err);
                              db.close();
      		    })
      		    console.log("after insert");
      		}
      		catch(e) { throw e; }
      	}
      );
      

            Assignee:
            christkv Christian Amor Kvalheim
            Reporter:
            joshua.maag@mongodb.com Joshua Maag
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: