添加一组数据有个user字段不允许重复,要检查没此字段时插入,有的话就跳过。这段要怎么写呢?翻find()用法好像没看到,能在没找到自动执行的方式。
闭关修行中......
Use the findOneAndUpdate method, and set upsert in the third parameter to true.
UserModel.findOneAndUpdate({_id: "asdasdadasd"}, req.newData, {upsert:true}, function(err, doc){});
http://stackoverflow.com/ques...http://mongoosejs.com/docs/ap...
Model.update({user:{"$in":["xxxx","xxxxxx"]}},{"$set":{}},{"upsert":true,},function (err,result){});
Use the findOneAndUpdate method, and set upsert in the third parameter to true.
http://stackoverflow.com/ques...
http://mongoosejs.com/docs/ap...