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. hadoop运行常见错误

    1)“no job jar file set”原因 又是被折腾了一下午呀~~,“no job jar file set”就是找不到作业jar包的意思,然后就是提示找不到自定义的MyMapper类,一般 ...

  2. dwz中弹出的窗口页面如何获取前页面(点击按钮的页面)的元素???

    在页面A.jsp中点击一个按钮,使用$.pdialog.open()方法弹出b.jsp页面(对话框窗口),我要在b.jsp中选中值然后关闭窗口(b.jsp)返回值给A.jsp~ =========== ...

  3. 如何订阅Linux相关的邮件列表

    转:http://blog.163.com/sunshine_linting/blog/static/44893323201282114012845/ 1.google"linux kern ...

  4. [Android Traffic] Android网络开启、关闭整理

    转载: http://blog.csdn.net/tu_bingbing/article/details/8469871 近段时间由于要对手机网络状况进行判断.开启和关闭,从网上找了些资料,现整理如下 ...

  5. Docker实践4: 基于nginx对后端的weblogic负载均衡

    为什么要用Nginx(抄了一段) 1.nginx相对于apache的优点: 轻量级,同样起web服务,比apache占用更少的内存及资源 抗并发,nginx处理请求是异步非阻塞的,而apache则是阻 ...

  6. leetcode笔记:Word Ladder

    一. 题目描写叙述 Given two words (start and end), and a dictionary, find the length of shortest transformat ...

  7. ASP.NET MVC file download sample

    ylbtech- ASP.NET MVC:ASP.NET MVC file download sample 功能描述:ASP.NET MVC file download sample 2,Techno ...

  8. 删除Kafka中topic

    步骤: 1.编辑Kafka启动时加载的配置文件server.properties,添加一行:delete.topic.enable=true 2.重启Zookeeper和Kafka 3.执行: ./b ...

  9. linux 输出重定向 何时会写文件

    linux 输出重定向 何时会写文件 测试到了8K才会进行flush:

  10. xubuntu openocd nRF51822 download --- 2

    昨天非常晚的时候才最终发现事实上Unkown USB Device并非错误,仅仅是个警告而已,所以我们不关心就能够.让Makefile继续往下走就能够.于是我尝试mbs,s110.cload和firm ...