GJain
GJain

Reputation: 5093

mongodb behavior when mongo server is stopped

I used Mongo with mongodb.MongoClient like this

var mongoClient = new MongoClient(new Server(mongoHost, mongoPort));
mongoClient.open(function(err, mongoClient) {
  if (!mongoClient) {
      logger.error("Error! Exiting... Must start MongoDB first");
      process.exit(1);
  }
  var dbName = config['mongo.db'];
  var db = mongoClient.db(dbName);
  collectionDriver = new CollectionDriver(db);
});

The above code works fine.

collectionDriver.save is defined as

//save new object
CollectionDriver.prototype.save = function(collectionName, obj, callback) {
    this.getCollection(collectionName, function(error, the_collection) {
      if( error ) callback(error)
      else {
        obj.created_at = new Date();
        the_collection.insert(obj, function(error, result) {
          if (error) callback(error)
          else callback(null, result);
        });
      }
    });
};

If I start mongodb again, it works as expected.

What is the expected behavior of CollectionDriver.prototype.save when I shutdown mongo server?

Upvotes: 0

Views: 124

Answers (1)

GJain
GJain

Reputation: 5093

I had partial understanding. After following thru

http://mongodb.github.io/node-mongodb-native/2.0/tutorials/connection_failures/

I found if I set bufferMaxEntries : 0, I start getting errors as expected.

By default mongodb buffers operartions.

Upvotes: 1

Related Questions