MongoDB增删查改
2016-01-19 16:46
573 查看
1.insert
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);
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的安装、主从配置、replicaSet配置
- MongoDB复制集自定义复制保证规则
- mongodb环境搭建
- MongoDB 基本命令
- [MONGODB]: WHEN ARBITER REQUIRED FOR REPLICA SET
- Centos 7下 mongodb 3.2.1 安装及权限配置
- Mongodb源码免编译安装
- mongodb不同版本之间有很大的差异
- MongoDB
- MongoDB的本地化排序
- CentOS6.4 安装MongoDB
- mongodb的几个基本命令
- MongoDB 初见指南
- MongoDB 初见指南
- MongoDB 初见指南
- MongoDB 初见指南
- MongoDB 基础(六)安全性(权限操作)
- MongoDB学习
- MongoDB使用小结:一些常用操作分享
- Data Base MongoDB常用命令