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++类的const成员函数、默认的构造函数、复制形参调用函数(转)

    C++类的const成员函数 double Sales_item::avg_price() const { } const关键字表明这是一个const成员函数,它不可以修改Sales_item类的成员 ...

  2. $_SERVER变量 以及 PHP 使用 $_SERVER['PHP_SELF'] 获取当前页面地址及其安全性问题

    PHP $_SERVER['PHP_SELF'] $_SERVER['PHP_SELF'] 表示当前 php 文件相对于网站根目录的位置地址,与 document root 相关. 假设我们有如下网址 ...

  3. [编译原理代码][NFA转DFA并最小化DFA并使用DFA进行词法分析]

    #include <iostream> #include <vector> #include <cstring> #include "stack" ...

  4. 1:scrapy框架原理与环境搭设

    1:原理图: (*此图来自网络) 2:开发过程: 1)编写items.py,确定要抓取的关键字段名称 2)编写spider,确定发送request的形式以及对于response的处理 3)编写pipe ...

  5. (转)ASP.NET 伪静态

    1.伪静态:http://www.cnblogs.com/Default.html 目的就是为了赢得更多的收入,至于真否,待SEOer 解答,正如文字所说,伪静态就是假的静态. 2.准备工作:下载Ur ...

  6. ORACLE查询数据库的锁表情况

      查询数据库的锁表情况语句如下: SELECT p.spid,a.serial#, c.object_name,b.session_id,b.oracle_username,b.os_user_na ...

  7. KM算法专题

    原文:http://972169909-qq-com.iteye.com/blog/1184514 题目地址:这里. 1)求图中所有环的总长度(环的长度不唯一)的最小值.当无法得到完备匹配时说明环不存 ...

  8. 01.Editplus+Lua配置

    学习一门语言有一款简单顺手的编辑工具很重要,我使用Editplus要多一点:就想能不能加上Lua支持,网上一搜还还不少.现把配置记录下来,也算做个笔记吧! Editplus版本是中文3.41(网上下吧 ...

  9. Jquery简略API使用

    都是个人随手笔记,既然开通了博客园就分享给大家.谨做为参考,具体大家自己测试以及使用 ★ $() ★ JQ的一个万能获取对象的函数(获取跟CSS获取元素是一样的)$(function(){}); 替代 ...

  10. PHP扩展开发(6) - VS2012下strncasecmp和fopen函数warning

    1. fopen   warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s i ...