当前位置:网站首页>Mongoose 的 存在则更新,不存在则新增
Mongoose 的 存在则更新,不存在则新增
2022-07-13 19:22:00 【itoof.com】
【findOneAndUpdate 】
- 存在则修改,不存在什么都不做
let mong_result = await this.case_main_keys_mongodb.findOneAndUpdate({
'name': '李四'
}, {
$set: {
'序列_1': '333',
}
}, {
})
- 存在则修改,并返回 修改后的数据,不存在什么都不做
let mong_result = await this.case_main_keys_mongodb.findOneAndUpdate({
'name': '李四'
}, {
$set: {
'序列_1': '333',
}
}, {
new: true})
- 存在则修改,不存在则新增,并返回(修改 或 新增 )后的数据,
let mong_result = await this.case_main_keys_mongodb.findOneAndUpdate({
'name': '李四'
}, {
$set: {
'序列_1': '333',
}
}, {
upsert: true, new: true})
注意:
$setOnInsert 和 $set中的属性记录不能相同
mongo更新语句使用$setOnInsert、$upsert和$set、$upsert的区别
对于查询到的记录。
使用$set、$upsert 存在则更新,不存在则新增
使用$setOnInsert、$upsert存在则不操作,不存在则新增
边栏推荐
- 成员函数之构造函数
- Otacle table query
- Orphan process, zombie process and process exit (for interview)
- np.delete详解 返回的数据为删除指定维度后的数据
- 如何报考PMP项目管理认证考试?
- Hcip day 5 notes
- 判断两棵二叉树是否同构,三种实现方式(递归、队列、堆栈)
- Password key hard coding check
- 音视频学习(六)——PCM音频基础
- Séquence de traversée de l'ordre initial et de l'ordre moyen pour déterminer un arbre binaire (restauration de l'arbre binaire)
猜你喜欢
随机推荐
CloudCompare&PCL 点云最小二乘法拟合平面
三种方法模拟实现库函数strlen,加深对strlen的理解
odoo的约束
内存映射原理及详解(非常实用)
vscode 输入 !不提示,没法自动补全的解决方法(最新)
Getting started with Scala
LeetCode 2155. All subscripts with the highest score in the group
What happens when you unplug the power? Gaussdb (for redis) dual life keeps you prepared
Extract the language you need from the multilingual data set and save it as CSV
babylon.js高度图
[Go]二、RESTful API介紹和API流程和代碼結構
Selected multiple choice questions of spark final exam
wait 和 waitpid 的区别
Various methods of obtaining form handle in VC
有名管道原理及详解(非常实用)
孤儿进程、僵尸进程和进程退出(针对面试)
Hcip second day notes
odoo多公司
C language register skills (struct and union)
天田AMADA数控折弯机触摸屏维修RGM21003主机电路板维修









