Mongodb 节点/MongoJS和批量操作

Mongodb 节点/MongoJS和批量操作,mongodb,mongojs,Mongodb,Mongojs,我有一个MongoDB 2.6数据库。 通过mongo shell,我能够按照预期执行批量操作,并使用mongo 1.4.9节点驱动程序: // 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(functi

我有一个MongoDB 2.6数据库。 通过mongo shell,我能够按照预期执行批量操作,并使用mongo 1.4.9节点驱动程序:

// 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, ...}
然而,在我的项目中,我使用的是MongoJS 0.14.1,它似乎是MongoDB 1.4.9节点驱动程序的包装器。如果我尝试使用此MongoJS包装器执行相同操作,我会得到:

// 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'
显然,当方法存在于驱动程序中时,包装器不会公开该方法。在MongoJS文档和Google中搜索时,我找不到任何与MongoJS驱动程序组合的批量操作相关的内容。我觉得这很奇怪,因为自5月左右以来,大宗业务一直存在

有人能告诉我如何使用MongoJS驱动程序执行Mongo批量操作吗? 是否得到支持?我的实现有什么问题吗


谢谢

显然,此MongoJS驱动程序还不支持批量更新。 MongoJS v0.15刚刚发布,支持批量更新。上面的示例使用这个更新的MongoJS驱动程序运行良好