数据查询 ######## :: # 查出所有数据 db..find().limit(30) # 等于 db..find({"key" : }) # 不等于 db..find({"key" :{$ne: }}) # 多条件and db..find({"key1" : , "key2" : }) # 多条件or db..find({$or : [{"key1" : }, {"key2" : }]}) # 查出一条数据 db..findOne() # 查出满足条件的一条数据 db..findOne({, }) # Match an Embedded Document db.inventory.find( { size: { h: 14, w: 21, uom: "cm" } } ) db.inventory.find( { "size.uom": "in" } ) # 根据数组字段部分匹配 # "red"是tags字段中的其中一个element db.inventory.find( { tags: "red" } ) # 数组的完全匹配 db.inventory.find( { tags: ["red", "blank"] } ) 指定返回的键:: # 只取出表中字段为的值 db..find({}, { : 1, : 1}) # 取出除字段之外的表的数据 db..find({}, { : 0}) 查询条件( ``$lt``, ``$lte``, ``$gt``, ``$gte`` 的使用 ):: db..find({ : {"$gte" : , "$lte" : } } ) ``$or``, ``$in`` 进行OR查询:: # $in db..find({ : {"$in" : [, ]}}) # $or db..find({"$or" : [{:}, {:}]}) ``$not`` 是元条件句, 即可以用在任何其他条件之上 使用 find 搜索子文档 ==================== find 支持使用“field.sub_field”的形式查询子文档。假设有一个文档:: db.fruit.insertOne({ name: "apple", from: { country: "China", province: "Guangdon" } }) 查询:: db.fruit.find( { "from.country" : "China" } ) db.fruit.find( { "from" : {country: "China"} } ) 使用 find 搜索数组 ================== ● find 支持对数组中的元素进行搜索。假设有一个文档:: db.fruit.insert([ { "name" : "Apple", color: ["red", "green" ] }, { "name" : "Mango", color: ["yellow", "green"] } ]) ● 考虑以下查询的意义:: db.fruit.find({color: "red"}) db.fruit.find({$or: [{color: "red"}, {color: "yellow"}]} )