mongodb更新器
Name Description
$inc Increments the value of the field by the specified amount.
$mul Multiplies the value of the field by the specified amount.
$rename Renames a field.
$setOnInsert Sets the value of a field if an update results in an insert of a document. Has no effect on update operations that modify existing documents.
$set Sets the value of a field in a document.
$unset Removes the specified field from a document.
$min Only updates the field if the specified value is less than the existing field value.
$max Only updates the field if the specified value is greater than the existing field value.
$currentDate Sets the value of a field to current date, either as a Date or a Timestamp.
https://docs.mongodb.com/manual/reference/operator/update-field/
> db.persons.insertOrUpdate({id:""}, {_id:"",name:"x0023"},true);
Sat Jun :: TypeError: db.persons.insertOrUpdate is not a function (she
l):
> db.persons.update({id:""}, {_id:"",name:"x0023"},true);
E11000 duplicate key error index: foobar.persons.$_id_ dup key: { : "" }
> db.persons.update({_id:""}, {_id:"",name:"x0023"},true);
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x0023" }
{ "_id" : "", "name" : "x03" }
> db.persons.update({_id:""}, {_id:"",name:"x03"},true);
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03" }
{ "_id" : "", "name" : "x03" }
> db.persons.update({name:"x03"}, {$set:{name:"x03"}},false,true);
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03" }
{ "_id" : "", "name" : "x03" }
> db.persons.update({name:"x03"}, {$set:{name:"x03sd"}},false,true);
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.person.update((name:""),{$set:{age:}})
Sat Jun :: SyntaxError: missing ) in parenthetical (shell):
> db.person.update({name:""},{$set:{age:}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.person.update({name:""},{$set:{age:}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.person.update({name:""},{$set:{age:}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.person.update({"name":""},{$set:{age:}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.person.update({"name":"x03sd"},{$set:{age:}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.persons.update({"name":"x03sd"},{$set:{age:}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "age" : , "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.persons.update({"name":"x03sd"},{$inc:{age:}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "age" : , "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.persons.update({"name":"x03sd"},{$inc:{age:-}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "age" : , "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.persons.update({"name":"x03sd"},{$unset:{age:}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.persons.update({"name":"x03sd"},{$push:{habby:"aa"}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "habby" : [ "aa" ], "name" : "x03sd" }
{ "_id" : "", "name" : "x03sd" }
> db.persons.update({"name":"x03sd"},{$push:{habby:"bb"}})
> db.persons.find()
{ "_id" : "", "name" : "" }
{ "_id" : "", "name" : "x03sd" }
{ "_id" : "", "habby" : [ "aa", "bb" ], "name" : "x03sd" }
> db.persons.update({"name":"x03sd"},{$push:{name:"bb"}})
Cannot apply $push/$pushAll modifier to non-array
>
mongodb更新器的更多相关文章
- Mongodb更新数组$pull修饰符 (mongodb 修改器($inc/$set/$unset/$push/$pop/upsert))
mongodb 修改器($inc/$set/$unset/$push/$pop/upsert)) https://www.jb51.net/article/112588.htm http://bl ...
- mongodb修改器
mongodb修改器 转载自:http://blog.csdn.net/mcpang/article/details/7752736 mongodb修改器(\(inc/\)set/\(unset/\) ...
- mongodb修改器(转)
MongoDB 修改器 对文档中的某些字段进行更新 $inc 专门用来增加(或减少)数字的,只能用于整数,长整数或双精度浮点型的值$inc键的值必须为数字,不能使用字符串,数组或其他非数字的值如果键不 ...
- MongoDB更新文档
说明:来看一下关系型数据库的update语句 UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某 其中where子句就类似查询文本,定位要更改的子表,set子句类似于修改器,更 ...
- mongoDB 修改器()
-----------------------------------2016-5-26 15:56:57-- source:[1],MongoDB更新操作符
- WinForm通用自动更新器AutoUpdater项目实战
一.项目背景介绍 最近单位开发一个项目,其中需要用到自动升级功能.因为自动升级是一个比较常用的功能,可能会在很多程序中用到,于是,我就想写一个自动升级的组件,在应用程序中,只需要引用这个自动升级组件, ...
- MongoDB——更新操作(Update)c#实现
c#实现 Mongodb存储[文档局部更新] 如下: 递归更新字段 ,构建UpdateDefinition /// <summary> /// 构建更新操作定义 /// &l ...
- Java原子属性更新器AtomicReferenceFieldUpdater的使用
AtomicReferenceFieldUpdater是基于反射的工具类,用来将指定类型的指定的volatile引用字段进行原子更新,对应的原子引用字段不能是private的.通常一个类volatil ...
- mongodb 更新数据时int32变为double的解决办法 & 教程
https://www.runoob.com/mongodb/mongodb-mongodump-mongorestore.html mongodb 更新数据时int32变为double的解决办法 ...
随机推荐
- Problem N: 猴子吃桃
#include<stdio.h> int main() { int n,s,i; while(scanf("%d",&n)!=EOF){ s=; ;i> ...
- jvm-监视管理控制台-jconsole
命令: jconsole 作用: jvm进程运行状态的实时.可视化工具 效果: 连接远程jvm进程: 1.首先远程jvm进程,开启了jmx服务: -Dcom.sun.management.jmxrem ...
- tcpreplay 发包速率控制算法研究
一. 序 1.1 tcpreplay历史 Tcpreplay 的作者是Aaron Turner,该项目开始于2000年,早期的功能是对tcpdump等抓包工具生成的网络包(即pcap文件)的回放, ...
- mysql 中查询一个字段是否为null的sql
查询mysql数据库表中字段为null的记录: select * 表名 where 字段名 is null 查询mysql数据库表中字段不为null的记录: select * 表名 where 字段名 ...
- WebLogic Server 12.1.2后的字符型安装模式
weblogic Server 12.1.1全部都可以用原来方式. WebLogic Server 12.1.2后已经取消了console安装模式,目前只有gui和静默安装模式.并且安装方式下也有很大 ...
- linux基础-第十八单元_nginx部署
一.基本环境配置 1.1.安装常用软件 yum install wget -y 1.2.Install yum repo mv /etc/yum.repos.d/CentOS-Base.repo /e ...
- ISP图像调试工程师——3D和2D降噪(熟悉图像预处理和后处理技术)
2D降噪:只在2维空间域上进行降噪处理.基本方法:对一个像素将其与周围像素平均,平均后噪声降低,但缺点是会造成画面模糊,特别是物体边缘部分.因此对这种算法的改进主要是进行边缘检测,边缘部分的像素不用来 ...
- 虚拟机设置NAT上网
需要开启虚拟机网络相关服务, 安装虚拟网卡VMware虚拟机下实现NAT方式上网1. 把你的虚拟网卡VMnet8设置为自动获得IP.自动获得DNS服务器,启用.2. 把你虚拟机中操作系统的“本地连接” ...
- Android项目总结
功能: 1.图片载入 ImageLoader 參数配置要合理 cacheMemory 一次性的图片最好不要缓存在内存中 合理控制在内存中的内存大小 ,适当的释放 volley是googl ...
- tomcat优化---大数据量提交tomcat时,tomcat无法接收导致页面无反应
关于tomcat的一个优化问题: 有时候保存大数据量的数据时.tomcat不优化的话,页面会没反应.tomcat后台并不报错,仅仅是提示以下内容: 警告: More than the maximum ...