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. STM3的Uart中断接受数据和非中断接受数据!

    //非中断方式接受数据if(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == SET) //接收数据寄存器非空标志位{ str = USART_Recei ...

  2. 简单说说DNS劫持_firefox吧_百度贴吧

    简单说说DNS劫持_firefox吧_百度贴吧 DNSSEC

  3. 直接拿来用!最火的Android开源项目(一)

    GitHub在中国的火爆程度无需多言,越来越多的开源项目迁移到GitHub平台上.更何况,基于不要重复造轮子的原则,了解当下比较流行的Android与iOS开源项目很是必要.利用这些项目,有时能够让你 ...

  4. Ado.Net基础拾遗二:插入,更新,删除数据

    插入数据 public void InsertDataToSQL() { string conStr = ConfigurationManager.ConnectionStrings["No ...

  5. go/golang init()方法的调用

    go/golang main() init()方法的调用 u011156212 · 2015-10-20 13:00:05 · 9965 次点击 · 预计阅读时间 1 分钟 · 27分钟之前 开始浏览 ...

  6. java源码阅读LinkedList

    1类签名与注释 public class LinkedList<E> extends AbstractSequentialList<E> implements List< ...

  7. Leagal or Not —— 拓扑排序(王道)

    Problem Description ACM-DIY is a large QQ group where many excellent acmers get together. It is so h ...

  8. Hex dump

    Hex dump From Wikipedia, the free encyclopedia       A hex dump of the 318 byte Wikipedia favicon In ...

  9. C# 代码生成器 (存储过程生成方法)

    最近研究C#,发现写代码很麻烦,特别是创建实体.模型.接口.工厂.存储过程之类,网上有些开源的,但是不完整,也不能完整的按需求生成,于是,花了三天的时候,结合前辈的一些经验,整合了一些代码生成器,以下 ...

  10. CSS/JavaScript hacks,browserhacks使用

    1.网址 http://browserhacks.com/ 2.使用 (1)JavaScript Hacks 浏览器js判断 (2)条件注释hack (3)Media Query Hacks 媒体查询 ...