2015-06-25 47 views
1

我試圖在Node.js中使用MongoDB 3.0.4中的Bulk update API。奇怪的是,如果使用$and$ne等運算符,我會得到下面的錯誤。簡單的查詢工作。

WriteError({"code":9,"index":0,"errmsg":"Unknown modifier: $and","op":{"q":{"$and":[{"id":49689},{"status":{"$ne":4}}]},"u":{"$and":[{"id":49689},{"status":{"$ne":4}}]},"multi":true,"upsert":false}}) 

下面是一些的CoffeeScript測試代碼:

bulk = db.mongo.collection('route-segments').initializeUnorderedBulkOp() 
    filter = $and: [ 
     { id: 49689 } 
     { status: $ne: 4 } 
    ] 
    # filter = id: segStatus.id # <-- this works 
    bulk.find(filter).updateOne(filter, $set: status: 4) 
    bulk.execute (err, result) -> 
    console.log "err = #{err}" 

我在蒙戈外殼嘗試相同的命令和它的工作:

> bulk=c.initializeUnorderedBulkOp() 
{ "nInsertOps" : 0, "nUpdateOps" : 0, "nRemoveOps" : 0, "nBatches" : 0 } 
> bulk.find({ $and: [{id: 49689}, {status: {$ne: 4}}]}).updateOne({$set: {status: 4}}) 
> bulk.execute() 
BulkWriteResult({ 
    "writeErrors" : [ ], 
    "writeConcernErrors" : [ ], 
    "nInserted" : 0, 
    "nUpserted" : 0, 
    "nMatched" : 1, 
    "nModified" : 1, 
    "nRemoved" : 0, 
    "upserted" : [ ] 
}) 

MongoDB的版本:3.0.4
的MongoDB Node.js驅動程序:2.0.35

回答

相關問題