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. Java多线程——ReentrantReadWriteLock源码阅读

    之前讲了<AQS源码阅读>和<ReentrantLock源码阅读>,本次将延续阅读下ReentrantReadWriteLock,建议没看过之前两篇文章的,先大概了解下,有些内 ...

  2. 使用ASP.Net WebAPI构建REST服务(七)——调试工具

    由于WebAPI本身是基于HTTP协议的,在开发过程中,我们可以使用浏览器或Fiddler等HTTP工具辅助开发.与此同时,微软也提供了一些工具方便我们调试,使得开发更加简单快捷,本文就简单的介绍一下 ...

  3. Linux Hook 笔记

    相信很多人对"Hook"都不会陌生,其中文翻译为"钩子".在编程中, 钩子表示一个可以允许编程者插入自定义程序的地方,通常是打包好的程序中提供的接口. 比如,我 ...

  4. github清理,记录一些有趣的项目

    1. rhino 一种java做的开源javascript引擎 https://github.com/mozilla/rhino 2. jeewx 国人写的公众号管理后台,集成度有些高,不好剥离.还是 ...

  5. 最佳eclipse字体推荐(个人觉得)

    首先大家能够看看这里面推荐的最佳十款字体.http://www.iteye.com/news/11102-10-great-programming-font 可是经过測试发现,排名第一的字体在ecli ...

  6. flask admin学习记录

    flask admin是flask框架中一个非常好用的后台管理框架,但是由于文档内容太少,经常遇到问题无法解决,这里记录一下 一简单的使用 from flask import Flask from f ...

  7. Python 自用代码(知网会议论文网页源代码清洗)

    #coding=utf-8 from pymongo import MongoClient from lxml import etree import requests jigou = u" ...

  8. 10 Essential TypeScript Tips And Tricks For Angular Devs

    原文: https://www.sitepoint.com/10-essential-typescript-tips-tricks-angular/ ------------------------- ...

  9. poj_1284_原根

    一開始看题的时候第一想法就是暴力,可是无奈数据量有点大,看了题解之后才知道原来牵扯到数论上的一个叫做原根的东西,这个题的题意就是,给你一个奇素数,问题他的原根有多少.依据初等数论上所说,此时牵扯到了三 ...

  10. linux 局域网内文件传送

    Linux scp命令用于Linux之间复制文件和目录,具体如何使用这里好好介绍一下,从本地复制到远程.从远程复制到本地是两种使用方式.这里有具体举例: ================== Linu ...