MongoDB find – 条件查询
MongoDB find – 条件查询
功能:按字段值搜索记录集
说明:如果存在符合条件的记录,find会返回这些符合条件的所有记录集的游标,在没有符合条件记录的时候,也返回一个空游标。
db.things.find({x:4}) 相当于select * from test where x = 4
db.things.find({x:4,y:5})相当于 select * fromtest where x = 4 and y = 5
例子1:
>db.things.find({x:4}).forEach(printjson)
>db.things.find({x:4,y:5}).forEach(printjson)
例子2– 体现其返回的是一个游标
>var cursor = db.things.find({x:4});
>cursor.next();
例子3– 体现其在没找到符合条件记录的时候,返回一个空游标
>var cursor = db.things.find({x:9}).next();
errorhasNext:false
(以上出错信息,显示其出错为没有下一条记录而已,而不是没有next方法,所以其为游标)
本文来源 我爱IT技术网 http://www.52ij.com/jishu/4818.html 转载请保留链接。
- 评论列表(网友评论仅供网友表达个人看法,并不表明本站同意其观点或证实其描述)
-
