[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++中的析构函数
代码: #include <cstdio> #include <iostream> using namespace std; class A{ public: ~A(){ co ...
- sublime3配置及插件安装
1.下载https://github.com/wbond/sublime_package_control中的zip文件,解压后将文件夹名更改为Package Control. 2.将1中的文件夹放入s ...
- Canvas -画图
2014-09-30 09:14:57 <!doctype html> <html> <head> <title> </title> < ...
- Javascript计算密码的强度
用Javascript评估用户输入密码的强度 1.如果密码少于5位,那么就认为这是一个弱密码.2.如果密码只由数字.小写字母.大写字母或其它特殊符号当中的一种组成,则认为这是一个弱密码.3.如果密码由 ...
- MySQL跨表更新字段 工作记录
工作中遇到两表查询,从user表中获取用户唯一id字段 写入到另外一张qiuzu表中的uid字段中; 二者可以关联起来的只有用户的手机号码tel字段; 了解需求后数据量稍多,不可能一个一个的手动修改 ...
- python编程中在ubuntu中安装虚拟环境及环境配置
1.升级python包管理工具pip pip install --upgrade pip 备注:当你想升级一个包的时候 `pip install --upgrade 包名` 2.python虚拟环境安 ...
- python 解决递归调用栈溢出
递归函数 2578次阅读 在函数内部,可以调用其他函数.如果一个函数在内部调用自身本身,这个函数就是递归函数. 举个例子,我们来计算阶乘n! = 1 x 2 x 3 x ... x n,用函数fact ...
- C程序设计语言练习题1-3
练习1-3 修改温度转换程序,使之能在转换表的顶部打印一个标题. 代码如下: #include <stdio.h> // 包含标准库的信息. int main() // 定义名为main的 ...
- Activiti工作流学习-----基于5.19.0版本(1)
该版本的Activiti运行须知: 1.JDK 6+,Eclipse最好是Kepler以上版本. 2.试验功能都有EXPERIMENTAL标注,被标注的部分不应该视为稳定的. 有兴趣的同学可以去了解下 ...
- Centos common software install
1.本地安装soft yum localinstall xxx.rpm 2.kolourpaintyum install kolourpaint