如何在sails中使用upsert,$ inc,$ set?

如何使用sails-mongo适配器在sails.js中使用“$ inc,$ set,upsert …”等mongodb操作?

我试过这个代码,但是适配器不能识别这个选项。

Word.update( {coincidence: 'aaaaa'}, {amount: 222}, {upsert:true,safe:true}, function(err,data){ if (err){ console.log(err); } else { console.log("score succeded"); } } ); 

你必须使用模型的native方法来做到这一点。 它返回本地Mongo驱动集合的一个实例:

 Word.native(function(err, collection) { collection.update( {coincidence: 'aaaaa'}, {amount: 222}, {upsert:true,safe:true}, function(err){ if (err){ console.log(err); } else { console.log("score succeded"); } } ); }); 

在这里查看关于Mongo本地驱动程序的文档,它将向您展示如何使用native方法返回的集合。