一、R(查询)
(1)查询ticket_no为725、542、390之一或者winner值为true的文档。
db.raffle.find({"$or" : [ {"ticket_no" : {"$in" :[725,542,390]}},{"winner":true}]})
(2)返回id_num为2,3,4,5,7,8,9,10,12等的用户。
db.users.find({"id_name" : {"not" : {"$mod" : [5,1]}}})
(3)找到fruit既有“apple”又有“banana”的文档,“$all”
db.food.find({"fruit" : {"$all" : ["apple","banana"]}})
现在有一个博客文章的文档,要求返回前10条评论。
db.blog.posts.findOne(criteria, {"comments" : {"$slice":10}})
(5)对内嵌文档的部分匹配 “$elemMatch”
db.blog.find({"comments" : {"$elemMatch":{"author":"joe","score":{"$gte" : 5}}})
(6)"$where" 可以执行任意JavaScript作为查询的一部分
db.foo.find({"$where" : "function(){ return this.x +this.y == 10;}"})
(7)limit,skip,sort的使用
db.stock.find({"desc" :"mp3"}).limit(50).skip(50).sort({"price" : -1})
二、U(查询)
第一个参数查询条件,
第二个参数显示内容,
第三个如果没有匹配到是否插入,
第四个是否支持多条查询
update({x:1},{$inc:{x:1}},false,true)