1

I have a MongoDB 2.6 database. From the mongo shell, I am able to perform bulk operations as expected, and using the Mongo 1.4.9 node driver as well:

// bulktest-mongodb.js:  works fine
var Db = require('mongodb').Db;
var Server = require('mongodb').Server;
var db = new Db('MyDB', new Server('localhost', 27017));

db.open(function(err, db) {
    var col = db.collection("MyCollection");

    var bulk = col.initializeUnorderedBulkOp();
    bulk.find({ _id: 1 }).update({ $inc: { bulk: 1 }});
    bulk.find({ _id: 2 }).update({ $inc: { bulk: 2 }});
    bulk.execute(function(err, result) {
        console.log("RESULT: "+JSON.stringify(result));
    });
});

RESULT: {"ok":1, ...}

However, in my project I am using MongoJS 0.14.1, which seems to be a wrapper for the MongoDB 1.4.9 node driver. If I try to do the same using this MongoJS wrapper, I get:

// bulktest-mongojs.js: does not work???
var mongojs = require("mongojs");
var db = mongojs.connect("mongodb://localhost/MyDB");
var col = db.collection("MyCollection");

var bulk = col.initializeUnorderedBulkOp();
bulk.find({ _id: 1}).update({ $inc: { bulk: 1}});
bulk.find({ _id: 2}).update({ $inc: { bulk: 2}});
bulk.execute(function(err, result) {
    console.log("RESULT: "+JSON.stringify(result));
});

> node ./bulktest-mongojs.js
...
var bulk = col.initializeUnorderedBulkOp();
               ^
TypeError: Object MyDB.MyCollection has no method 'initializeUnorderedBulkOp'

Apparently the method is not exposed by the wrapper, while it is present in the driver. When searching in the MongoJS docs and in Google I cannot find anything related to bulk operations in combination with the MongoJS driver. I find this curious, as bulk operations have been around since May or so.

Can anybody tell me how to perform Mongo bulk operations with the MongoJS driver? Is it supported at all? Something wrong with my implementation?

Thanks!

ECA
  • 33
  • 1
  • 6

1 Answers1

0

Apparently bulk updates were not supported yet with this MongoJS driver. MongoJS v0.15 was just released and supports bulk updates. The above example worked fine with this updated MongoJS driver.

ECA
  • 33
  • 1
  • 6