Remove:

remove the wand with the name of "Doom Bringer" from our wandscollection.

db.wands.remove({name: "Doom Bringer"})

>> WriteResult({'ngRemoved': 1})

When we removed the "Doom Bringer" wand, we noticed that it had a power of "Death", and we don't want any wands like that in our database. To be safe, let's remove any wands containing that in their powers.

db.wands.remove({name: "Doom Bringer", powers: "Death"})

Update:

Write the command to update the wand with a name of "Devotion Shift" and set the price to 5.99.

db.wands.update({name: "Devotion Shift"},{"$set": {price: 5.99}});

Update all the document: "multi"

Increase level_required by 2, apply to all the documents match {powers: "Fire"}:

db.wands.update(
{powers: "Fire"},
{"$inc":{level_required: 2}},
{"multi": true}
)

Create new document if there is no existing one: "upsert"

db.logs.update(
{name: "Dream Bender"},
{"$inc": {count: 1}},
{"upsert": true}
)

[MongoDB] Remove, update, create document的更多相关文章

  1. MongoDB的update有关问题(JAVA)——如何一次更新所有的相同记录

    MongoDB的update问题(JAVA)——怎么一次更新所有的相同记录用如下这个函数:public WriteResult update(DBObject q,  DBObject o,  boo ...

  2. Mongodb 语法,update,insert,delete,find

    ---恢复内容开始--- db.Users.update({OrganizationCode:"Global"},{$set:{OrganizationCode:"Fre ...

  3. [MongoDB] Query, update, index and group

    /* 1. Query Operators */ db.posts.find({ viewsCount: {$get: 1000, $lte: 3000} }, {_id: 0, viewsCount ...

  4. mongodb remove删除文档的用法

    在看<mongoDB权威指南>中,在删除文档时,出现问题: 书中介绍:采用db.foo.remove()命令则可以删除foo集合中所有的文档,但是在执行该命令时,shell客户端却报错. ...

  5. MongoDB统计文档(Document)的数组(Array)中的各个元素出现的次数

    一,问题描述 [使用 unwind 操作符 “解包” Document 里面的Array中的每个元素,然后使用 group 分组统计,最后使用 sort 对分组结果排序] 从 images.json ...

  6. MongoDB之update

    Update操作只作用于集合中存在的文档.MongoDB提供了如下方法来更新集合中的文档: db.collection.update() db.collection.updateOne() New i ...

  7. python 集合set remove update add

    1. 集合(set):把不同的元素组成一起形成集合,是python基本的数据类型. 集合对象是一组无序排列hashable value:集合成员可以做字典的键. 集合就像是 list 和 dict 的 ...

  8. [AngularFire 2] Push, remove, update

    import { Injectable } from '@angular/core'; import {RealtimeService} from "../shared"; imp ...

  9. MongoDB(5)- Document 文档相关

    Documents MongoDB 的文档可以理解为关系型数据库(Mysql)的一行记录 MongoDB 将数据记录为 BSON 格式的文档 BSON 是 JSON 文档的二进制表示,但它支持的数据类 ...

随机推荐

  1. C程序设计的抽象思维-算法分析-大多数元素

    [问题] 请编写下面函数 int MajorityElement(int array[],int n); 该函数返回数组array中的多数元素.多数元素是指在占绝对多数(至少51%)的一个值.假设多数 ...

  2. 大数据笔记11:MapReduce的运行流程

    1.基本概念 (1)Job & Task (2)JobTracker (3)TaskTracker

  3. 关于ubuntu中的软件安装

    在ubuntu中一般使用apt-get来安装软件工具, 例如 sudo apt-get install g++ apt-get会在镜像库中找到你需要的软件镜像(例如 g++)来安装,那么apt-get ...

  4. .IIS7如何设置301重定向详解

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.we ...

  5. (转)弹出窗口lhgDialog API文档

    应用到你的项目 如果您使用独立版本的lhgDialog窗口组件,您只需在页面head中引入lhgcore.lhgdialog.min.js文件,4.1.1+版本做了修改可以和jQuerya库同时引用, ...

  6. Android -------- 用XmlPullParser解析器解析XML文件

  7. SSAS数据集Cube不存在或者尚未处理

    对Microsoft SQL Server(2008) Analysis Services(以下称SSAS) 多维数据集运行多维表达式 (MDX) 查询时,会返回这个错误消息:XXX Cube不存在, ...

  8. 拦截Response.Redirect的跳转并转换为Js的跳转

    有一个很常见的需求,某个页面需要用户登录才能访问,或者某个操作需要用户登录 这就需要检测用户登录,一般是使用Ajax去检测是否登录,当用户未登录时跳转到登录页面 那么问题来了···· 有的时候我们跳转 ...

  9. servlet 具体实现

    1)servlet 具体实现 1.在GenericServlet中声明了一个ServletConfig类型的成员变量,在init(ServletConfig)方法中对其进行了初始化 2.利用servl ...

  10. mysql与java数据类型对应关系