Mongoose versionKey在更新的where子句中没有显示

我正在试图获得在mongoose工作的版本,以防止并发修改。 我已经构build了一个testing,我在帐户中读取两次(帐户1和帐户2)修改帐户1保存它,修改帐户2保存它,并期望版本号错误。

it('check concurrent updates using the __v operator', function (done) { Account.readAccount(localTestData.mumAccountId, function (err, account1) { console.log('account1 with metadata : ', account1); Account.readAccount(localTestData.mumAccountId, function (err, account2) { console.log('account2 with metadata : ', account2); //both accounts should be the same at this point. account1.settings.annotationsDisplayed.push('account1 new text'); //account1.increment(); account1.save(function (err, account1saved) { console.log('account1 after save -- version inc : ', account1saved); account2.settings.annotationsDisplayed.push('account2 new text'); account2.save(function (err, account2saved) { //shoould throw an error console.log('account2 after save : ', account2saved); console.log('account2 err : ', err); expect(err).to.not.be(null); done(); }); }); }); }); }); 

上面的失败,最后一次写入胜利。 Mongoosedebugging显示了以下更新: Mongoose: accounts.update({ _id: ObjectId("54e747c59b5ff6153f000001") }) { '$inc': { __v: 1 }, '$pushAll': { 'settings.annotationsDisplayed': [ 'account1 new text' ] }, '$set': { lastModified: new Date("Fri, 20 Feb 2015 14:42:14 GMT") } } {}

第二个: Mongoose: accounts.update({ _id: ObjectId("54e747c59b5ff6153f000001") }) { '$inc': { __v: 1 }, '$pushAll': { 'settings.annotationsDisplayed': [ 'account2 new text' ] }, '$set': { lastModified: new Date("Fri, 20 Feb 2015 14:42:14 GMT") } } {}

我希望更新的where子句包含__v字段,以便versionKey代码可以正常工作,但不会看到它发生。 我已经阅读这个博客http://aaronheckmann.tumblr.com/post/48943525537/mongoose-v3-part-1-versioning这似乎是唯一真正的文件,但目前没有帮助。 我正在更新数组,因为这似乎强制基于文档的增量,但如果我手动调用也失败的增量方法。

任何帮助非常感谢。

Interesting Posts