MongoDB增删查改
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增删查改的更多相关文章
- [MongoDB] MongoDB增删查改
MongoDB的三元素,数据库.集合.文档,集合就是表,文档就是行 开启MongoDB,cd切换到MongoDB的安装目录下的bin目录里,使用命令mongod 开启,参数:--dbpath 路径,把 ...
- 8天学通MongoDB——第二天 细说增删查改
原文地址:http://www.cnblogs.com/huangxincheng/archive/2012/02/19/2357846.html 看过上一篇,相信大家都会知道如何开启mongodb了 ...
- MongoDB数据库(二):增删查改
MongoDB数据库的增删查改 1.插入数据 语法: db.集合名称.insert(document) db.table_name.insert({name:'gj',gender:1}) db.ta ...
- MongoDB的增删查改基本操作
MongoDB的增删查改基本操作 先决条件建库.建集合.建文档 连接mongo,如果连接不上什么连接拒绝,输入mongod命令,启动服务后 输入mongo show dbs 显示当前的所有的数据库 一 ...
- MongoDB在Java下的增删查改
我们总不能一直使用cmd对数据库操作,数据库总是要在程序中使用的.今天来说一下怎么通过Java调用MongoDB. 学习一下最基本也是最常用的增删查改语句,这是使用数据库的基础. 注意事项: 1.要打 ...
- MongoDB入门学习(三):MongoDB的增删查改
对于我们这样的菜鸟来说,最重要的不是数据库的管理,也不是数据库的性能,更不是数据库的扩展,而是怎么用好这款数据库,也就是一个数据库提供的最核心的功能,增删查改. 由于M ...
- node.js+express+mongoose实现用户增删查改案例
node.js+express+mongodb对用户进行增删查改 一.用到的相关技术 使用 Node.js 的 express 框架搭建web服务 使用 express 中间件 body-parse ...
- 6.在MVC中使用泛型仓储模式和依赖注入实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-the-generic-repository-pat ...
- 3.EF 6.0 Code-First实现增删查改
原文链接:http://www.c-sharpcorner.com/UploadFile/3d39b4/crud-operations-using-entity-framework-5-0-code- ...
随机推荐
- $.extend()了解心得
2.1 extend(result,item1,item2-..) 这里这个方法主要用来合并,将所有的参数项都合并result中,并返回result,但是这 样就会破坏result的结构. 2.2 e ...
- Mysql中索引的 创建,查看,删除,修改
创建索引 MySQL创建索引的语法如下: ? 1 2 3 CREATE [UNIQUE|FULLTEXT|SPATIAL] INDEX index_name [USING index_type] ON ...
- 21 BasicTaskScheduler基本任务调度器(一)——Live555源码阅读(一)任务调度相关类
21_BasicTaskScheduler基本任务调度器(一)——Live555源码阅读(一)任务调度相关类 BasicTaskScheduler基本任务调度器 BasicTaskScheduler基 ...
- django初始
创建django工程 django-admin startproject [工程名称] mysite - mysite # 对整个程序进行配置 - init - settings # 配置文件 - u ...
- ndk学习15: IPC机制
Linux IPC机制 来自为知笔记(Wiz)
- Git引用
原文: http://gitbook.liuhui998.com/7_3.html git中,分支(branch), 远程跟踪分支(remote-tracking branch)以及标签(tag)都是 ...
- Node.JS初识
对Node.JS的认识 1.Node 是一个服务器端 JavaScript 解释器: 2.Node 的目标是帮助程序员构建高度可伸缩的应用程序,编写能够处理数万条同时连接到一个物理机的连接代码.处理高 ...
- sharepoint2010匿名访问
怎样在SharePoint 2010网站中启用匿名访问 SharePoint 2010的改动比较大,尤其是相对SharePoint Portal Server 2003来说.本文介绍在SharePoi ...
- Unity3d 防止内存修改工具的小方法
一个非常简单的方法,直接上代码. private int curATK; private int curAtkKey; public int CurATK { get { return curATK ...
- Java for LeetCode 222 Count Complete Tree Nodes
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from W ...