扫码关注官方订阅号
添加一组数据有个user字段不允许重复,要检查没此字段时插入,有的话就跳过。这段要怎么写呢?翻find()用法好像没看到,能在没找到自动执行的方式。
闭关修行中......
使用findOneAndUpdate方法,第三个参数里面的upsert设为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){});
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
使用findOneAndUpdate方法,第三个参数里面的upsert设为true。
http://stackoverflow.com/ques...
http://mongoosejs.com/docs/ap...