摘要: 可以通过包装来使用mongo的高级查询。$maxscan:integer 指定查询最多扫描的文档数量。$min:document 查询的开始条件$max:document 查询的结束条件$hint:document 指定服务器使用哪个索引进行查询。$explain:boolean 获取查询执行的细节,而并非真正执行查询。$snapshot:boolean 确保查询的结果是在查询执行那一刻的一致快照。例如 $explain:> db.tianyc05.find().limit(2).skip(1).sort({age:1}).explain(){ "cursor" : 阅读全文
posted @ 2013-02-04 15:25 醇酒醉影 阅读(1604) 评论(0) 推荐(0) 编辑
摘要: 使用游标。> db.tianyc05.find(){ "_id" : 1, "age" : 32, "name" : { "first" : "tian", "last" : "yc" }, "sex" : "m" }{ "_id" : 2, "age" : 27, "name" : { "first" : "tian&q 阅读全文
posted @ 2013-02-04 15:09 醇酒醉影 阅读(1744) 评论(0) 推荐(0) 编辑
摘要: 查询mongo的内嵌文档。> db.tianyc05.find(){ "_id" : 1, "name" : { "first" : "tian", "last" : "yc" } }{ "_id" : 2, "name" : { "first" : "tian", "last" : "yx" } }{ "_id" : 3, &qu 阅读全文
posted @ 2013-02-04 14:53 醇酒醉影 阅读(1978) 评论(0) 推荐(0) 编辑
摘要: 查询数组。此时你可能会使用到$all、$size。> db.tianyc04.find(){ "_id" : 1, "fruit" : [ "apple", "banana", "peach" ] }{ "_id" : 2, "fruit" : [ "apple", "orange", "peach" ] }{ "_id" : 3, "fruit" : 阅读全文
posted @ 2013-02-04 11:53 醇酒醉影 阅读(17842) 评论(0) 推荐(0) 编辑
摘要: mongo的find中,还可以使用正则表达式。> db.tianyc02.find({name:/xTtt/i}){ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xttt", "a 阅读全文
posted @ 2013-02-04 11:41 醇酒醉影 阅读(5331) 评论(0) 推荐(0) 编辑
摘要: 关于null:若某列值为null,则设置条件null查询时,会返回该行文档,但同时还会返回不存在该列的文档。> db.tianyc02.find(){ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xt 阅读全文
posted @ 2013-02-04 11:36 醇酒醉影 阅读(3611) 评论(0) 推荐(0) 编辑
摘要: mongo通find来查找文档。可以执行精确匹配和模糊匹配。2. 模糊匹配2.1比较> $gt , >= $gte, < $lt, <= $lte, != $ne> db.tianyc02.find(){ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }{ "_id" : ObjectId("50ea6eba12729d90ce6e3 阅读全文
posted @ 2013-02-04 11:28 醇酒醉影 阅读(51401) 评论(0) 推荐(1) 编辑
摘要: mongo通find来查找文档。可以执行精确匹配和模糊匹配。1. 精确匹配#查询全部> db.tianyc02.find(){ "_id" : ObjectId("50ea6eba12729d90ce6e3423"), "name" : "xttt", "age" : 111 }{ "_id" : ObjectId("50ea6eba12729d90ce6e3424"), "name" : "xttt", &q 阅读全文
posted @ 2013-02-04 11:07 醇酒醉影 阅读(6351) 评论(0) 推荐(1) 编辑
摘要: 1. upsert将update的第三个参数设置为true,存在则更新,不存在则插入。> db.tianyc03.find(){ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "age" : 16, "companies" : [ "teletek" ], "name" : "xtt" }> db.tianyc03.update({count:20},{$inc:{count:3}}, true)& 阅读全文
posted @ 2013-02-04 10:44 醇酒醉影 阅读(7133) 评论(0) 推荐(0) 编辑
摘要: 除了查询条件,还可以使用修改器对文档进行更新。1. $inc> db.tianyc03.find(){ "_id" : ObjectId("50ea6b6f12729d90ce6e341b"), "name" : "xtt", "age" : 11 }> db.tianyc03.update({name:'xtt',age:11},{'$inc':{age:5}})> db.tianyc03.find(){ "_id" : O 阅读全文
posted @ 2013-02-04 09:31 醇酒醉影 阅读(15305) 评论(0) 推荐(0) 编辑