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更新器的更多相关文章

  1. 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 ...

  2. mongodb修改器

    mongodb修改器 转载自:http://blog.csdn.net/mcpang/article/details/7752736 mongodb修改器(\(inc/\)set/\(unset/\) ...

  3. mongodb修改器(转)

    MongoDB 修改器 对文档中的某些字段进行更新 $inc 专门用来增加(或减少)数字的,只能用于整数,长整数或双精度浮点型的值$inc键的值必须为数字,不能使用字符串,数组或其他非数字的值如果键不 ...

  4. MongoDB更新文档

    说明:来看一下关系型数据库的update语句 UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某 其中where子句就类似查询文本,定位要更改的子表,set子句类似于修改器,更 ...

  5. mongoDB 修改器()

    -----------------------------------2016-5-26 15:56:57-- source:[1],MongoDB更新操作符

  6. WinForm通用自动更新器AutoUpdater项目实战

    一.项目背景介绍 最近单位开发一个项目,其中需要用到自动升级功能.因为自动升级是一个比较常用的功能,可能会在很多程序中用到,于是,我就想写一个自动升级的组件,在应用程序中,只需要引用这个自动升级组件, ...

  7. MongoDB——更新操作(Update)c#实现

    c#实现 Mongodb存储[文档局部更新] 如下: 递归更新字段  ,构建UpdateDefinition   /// <summary>   /// 构建更新操作定义   /// &l ...

  8. Java原子属性更新器AtomicReferenceFieldUpdater的使用

    AtomicReferenceFieldUpdater是基于反射的工具类,用来将指定类型的指定的volatile引用字段进行原子更新,对应的原子引用字段不能是private的.通常一个类volatil ...

  9. mongodb 更新数据时int32变为double的解决办法 & 教程

    https://www.runoob.com/mongodb/mongodb-mongodump-mongorestore.html mongodb 更新数据时int32变为double的解决办法   ...

随机推荐

  1. 1.2(学习笔记) JSP动作元素

    动作元素 jsp:useBean:根据指定类实例化一个对象,类似Preson per = new Preson(); <jsp:useBean id="对象名" class ...

  2. Enable a SQL Server Trace Flag Globally on Linux

    https://www.mssqltips.com/sql-server-tip-category/226/sql-server-on-linux// Microsoft has recently r ...

  3. win10 彻底删除mysql步骤

    转载自:https://blog.csdn.net/sxingming/article/details/52601250 1. 停止MySQL服务 开始->所有应用->Windows管理工 ...

  4. JavaScript字符串api简单说明

    1.可返回指定位置的字符 stringObject.charAt(index); 2.返回的是位于指定位置的字符的编码 stringObject.charCodeAt(index); 3.用于连接两个 ...

  5. easyUI中datagrid控制获取指定行数的数据

    直接上代码: var rows=$('#detail').datagrid('getRows');//获取所有当前加载的数据行 var row=rows[0];// 行数从 0 开始 项目中代码: v ...

  6. Virtualbox环境中安装Oracle 11gr2 RAC(ASM)

    系统Oracle Linux 6.5,Oracle 11.2.0.1 终于开始安装ASM和RAC的行程了.开始前需要想清楚的几个事情: 如何规划网络配置(配置多网卡,实现连通性,规划内外网,eth0, ...

  7. linux中查找文件属于那个软件包的方法

    一.linux中查找文件属于那个软件包的方法 [root@salt prod]# whereis htpasswdhtpasswd: /usr/bin/htpasswd /usr/share/man/ ...

  8. javascript快速入门11--正则表达式

    正则表达式可以: 测试字符串的某个模式.例如,可以对一个输入字符串进行测试,看在该字符串是否存在一个电话号码模式或一个信用卡号码模式.这称为数据有效性验证 替换文本.可以在文档中使用一个正则表达式来标 ...

  9. D3.js系列——初步使用、选择元素与绑定数据

    D3 的全称是(Data-Driven Documents),顾名思义可以知道是一个被数据驱动的文档.听名字有点抽象,说简单一点,其实就是一个 JavaScript 的函数库,使用它主要是用来做数据可 ...

  10. android中实现内容搜索

    在编写android搜索代码的时候,怎样去实现搜索功能,考虑中的有两种: 自己定义搜索方法: 1.自己定义搜索输入框,搜索图标,搜索button 2.自己定义语音输入方法 3.自己定义经常使用热词内容 ...