[MongoDB] Remove, update, create document
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的更多相关文章
- MongoDB的update有关问题(JAVA)——如何一次更新所有的相同记录
MongoDB的update问题(JAVA)——怎么一次更新所有的相同记录用如下这个函数:public WriteResult update(DBObject q, DBObject o, boo ...
- Mongodb 语法,update,insert,delete,find
---恢复内容开始--- db.Users.update({OrganizationCode:"Global"},{$set:{OrganizationCode:"Fre ...
- [MongoDB] Query, update, index and group
/* 1. Query Operators */ db.posts.find({ viewsCount: {$get: 1000, $lte: 3000} }, {_id: 0, viewsCount ...
- mongodb remove删除文档的用法
在看<mongoDB权威指南>中,在删除文档时,出现问题: 书中介绍:采用db.foo.remove()命令则可以删除foo集合中所有的文档,但是在执行该命令时,shell客户端却报错. ...
- MongoDB统计文档(Document)的数组(Array)中的各个元素出现的次数
一,问题描述 [使用 unwind 操作符 “解包” Document 里面的Array中的每个元素,然后使用 group 分组统计,最后使用 sort 对分组结果排序] 从 images.json ...
- MongoDB之update
Update操作只作用于集合中存在的文档.MongoDB提供了如下方法来更新集合中的文档: db.collection.update() db.collection.updateOne() New i ...
- python 集合set remove update add
1. 集合(set):把不同的元素组成一起形成集合,是python基本的数据类型. 集合对象是一组无序排列hashable value:集合成员可以做字典的键. 集合就像是 list 和 dict 的 ...
- [AngularFire 2] Push, remove, update
import { Injectable } from '@angular/core'; import {RealtimeService} from "../shared"; imp ...
- MongoDB(5)- Document 文档相关
Documents MongoDB 的文档可以理解为关系型数据库(Mysql)的一行记录 MongoDB 将数据记录为 BSON 格式的文档 BSON 是 JSON 文档的二进制表示,但它支持的数据类 ...
随机推荐
- C#。3.1 循环(叠加、穷举)
循环. for 循环 嵌套的应用, 迭代.穷举 一.迭代法 每次循环都是从上次运算结果中获得数据,本次运算的结果都是要为下次运算做准备.例:1.100以内所有数的和. int sum = 0; for ...
- easyui 点击combox 文本框 显示下拉 panel
$(".combo-text").click(function () { var mid = $(this).parent().parent().find("select ...
- DropDownList获取的SelectIndex一直为0
1.想要DropDownList自动提交必须设置AutoPostBack="true"属性,下面是代码: <asp:DropDownList ID=" AutoPo ...
- linux 各种发行版及包管理器的关系
linux 各种发行版及包管理器的关系 Linux发行版列表 基于Kpkg(Debian 系) Debian GNU / Linux 及其派生发行版使用deb软件包格式,并使用dpkg及其前端作为包管 ...
- DataBase First创建数据库
Entity Framework:ADO.NET Entity Framework 是微软以 ADO.NET 为基础所发展出来的对象关系对应 (O/R Mapping) 解决方案,并提供了三种模式,分 ...
- Hashtable键值集合
//Hashtable键值集合 键必须是维一的 类似于索引 Hashtable ht = new Hashtable(); ht.Add(, "中国"); ht.Add(, ); ...
- Word 2010发布博客文章
只测试了cnblog 1.新建文件选择word 2010自带的博客文章模板 2.在管理账户中新建一个博客账户,也就是你自己在博客园的账户,博客选其他 3.然后选择下一步,博客的URL在自己的博客设置里 ...
- django 自定用户系统 以及 Django Model 定义语法
http://www.tuicool.com/articles/jMzIr2 django使用自己的用户系统 http://www.jianshu.com/p/c10be59aad7a Django ...
- WPF、WinForm(C#)多线程编程并更新界面(UI)(转载积累)
using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using ...
- JQuery 判断ie7|| ie8
if( $.browser.msie && ( $.browser.version == '7.0' || $.browser.version == '8.0'|| $.browser ...