1.insert

db.Customers.insert({
"DateTest":new Date(),
"IntTest":32,
"DoubleTest":3.1415926,
"StringTest":"Test",
"BoolTest":true,
"ArryTest":["a", "b", "c"],
"aaa":undefined,
"info" : { "x" : 203 ,"y" : 102}
});

2.find

<1>"$gt", "$gte", "$lt", "$lte", "$ne"
--where IntTest>30
db.Customers.find({ "IntTest" : { "$gt" : 30 } })
--where IntTest<30
db.Customers.find({ "IntTest" : { "$lt" : 30 } })
--where IntTest!=1
db.Customers.find({ "IntTest" : { "$ne" : 1 } })
--where IntTest==30
db.Customers.find({ "IntTest" : 30 })
<2>"$or", "$in","$nin"
--where FirstName="Bobr"
db.Customers.find({ "FirstName" : "Bobr" })
--where FirstName="Bobr" or FirstName="Bobr1"
db.Customers.find({ "$or" : [{ "FirstName" : "Bobr" }, { "FirstName" : "Bobr1" }] })
--where FirstName="Bobr" and LastName="Dillon"
db.Customers.find({ "FirstName" : "Bobr", "LastName" : "Dillon" })
--where FirstName in ("Bobr","Bobr1")
db.Customers.find({ "FirstName" : { "$in" : ["Bobr", "Bobr1"] } })
--where FirstName not in ("Bobr","Bobr1") 没有"FirstName"的也会找出来
db.Customers.find({ "FirstName" : { "$nin" : ["Bobr", "Bobr1"] } })

<3>正则表达式
--FirstName K开头
db.Customers.find({ "FirstName" : /^K/ })
--FirstName like '%Bob%'
db.Customers.find({ "FirstName" : /Bob/ })
<4>$where
db.Customers.find({ "$where" : "this.FirstName == 'KBobr'" })

3.Update $inc(没有就新增,有就在原有基础上添加) 和 $set
db.Customers.update({ "FirstName" : /Bob/, "$atomic" : "true" },{$inc:{"age":500}}, false, true)
db.Customers.update({ "FirstName" : /Bob/, "$atomic" : "true" },{$set:{"age":500}}, false, true)

4.Remove
db.Customers.remove({ "_id" : ObjectId("567b55a50e906e261435dafb") }, $atomic: true);
db.Customers.remove({ "FirstName" : "KBobr" }, $atomic: true);

MongoDB增删查改的更多相关文章

  1. [MongoDB] MongoDB增删查改

    MongoDB的三元素,数据库.集合.文档,集合就是表,文档就是行 开启MongoDB,cd切换到MongoDB的安装目录下的bin目录里,使用命令mongod 开启,参数:--dbpath 路径,把 ...

  2. 8天学通MongoDB——第二天 细说增删查改

    原文地址:http://www.cnblogs.com/huangxincheng/archive/2012/02/19/2357846.html 看过上一篇,相信大家都会知道如何开启mongodb了 ...

  3. MongoDB数据库(二):增删查改

    MongoDB数据库的增删查改 1.插入数据 语法: db.集合名称.insert(document) db.table_name.insert({name:'gj',gender:1}) db.ta ...

  4. MongoDB的增删查改基本操作

    MongoDB的增删查改基本操作 先决条件建库.建集合.建文档 连接mongo,如果连接不上什么连接拒绝,输入mongod命令,启动服务后 输入mongo show dbs 显示当前的所有的数据库 一 ...

  5. MongoDB在Java下的增删查改

    我们总不能一直使用cmd对数据库操作,数据库总是要在程序中使用的.今天来说一下怎么通过Java调用MongoDB. 学习一下最基本也是最常用的增删查改语句,这是使用数据库的基础. 注意事项: 1.要打 ...

  6. MongoDB入门学习(三):MongoDB的增删查改

            对于我们这样的菜鸟来说,最重要的不是数据库的管理,也不是数据库的性能,更不是数据库的扩展,而是怎么用好这款数据库,也就是一个数据库提供的最核心的功能,增删查改.         由于M ...

  7. node.js+express+mongoose实现用户增删查改案例

    node.js+express+mongodb对用户进行增删查改 一.用到的相关技术 使用 Node.js 的 express 框架搭建web服务 使用 express 中间件 body-parse ...

  8. 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...

  9. 3.EF 6.0 Code-First实现增删查改

    原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-entity-framework-5-0-code- ...

随机推荐

  1. [POJ3277]City Horizon

    [POJ3277]City Horizon 试题描述 Farmer John has taken his cows on a trip to the city! As the sun sets, th ...

  2. Win10主题打不开,自动弹出桌面图标设置

    把官方下载的主题文件扩展名改成.deskthemepack,然后双击主题文件就可以正常使用了.

  3. Android学习之路书籍推荐

    Android开发书籍推荐:从入门到精通系列学习路线书籍介绍 JAVA入门书籍: < Introduction to java programming > < Core java & ...

  4. OpenCv haar+SVM训练的xml检测人头位置

    注意:opencv-2.4.10 #include "stdio.h"#include "string.h"#include "iostream&qu ...

  5. 借助 SublimeLinter 编写高质量的 JavaScript & CSS 代码

    SublimeLinter 是前端编码利器——Sublime Text 的一款插件,用于高亮提示用户编写的代码中存在的不规范和错误的写法,支持 JavaScript.CSS.HTML.Java.PHP ...

  6. [转]Unchecked Exception 和 Checked Exception 比较

    Throwable类是所有异常的始祖,它有两个直接子类Error / Exception:   Error仅在Java虚拟机中发生动态连接失败或其它的定位失败的时候抛出一个Error对象.一般程序不用 ...

  7. hadoop MapReduce Yarn运行机制

    原 Hadoop MapReduce 框架的问题 原hadoop的MapReduce框架图 从上图中可以清楚的看出原 MapReduce 程序的流程及设计思路: 首先用户程序 (JobClient) ...

  8. nginx 原理&知识

    2015年6月4日 17:04:20 星期四 发现两个关于nginx原理的系列文章, 非常好 http://blog.sina.com.cn/s/blog_6d579ff40100wi7p.html ...

  9. 4. javacript高级程序设计-变量、作用域和内存问题

    1.1 基本类型和引用类型的值 变量包含两种不同数据类型的值:基本类型值和引用类型值.基本类型值指的是简单的数据段,引用类型值可以由多个值构成的对象 1.1.1 动态的属性 针对引用对象的值,可以为其 ...

  10. Effective C++ -----条款16:成对使用new和delete时要采取相同形式

    如果你在new表达式中使用[],必须在相应的delete表达式中也使用[].如果你在new表达式中不使用[],一定不要在相应的delete表达式中使用[].