Find查询是MongoDB中最基本也是最常用的语法。使用起来也非常简单。下面列出了Find的一些基本操作。
> db.news.find() //select * from [news]
{ "_id" : 10001, "count" : 1, "news" : "i hava a dream", "time" : ISODate("2011-09-05T13:40:58.034Z") }
{ "_id" : 10002, "count" : 2, "news" : "wow! it is very good!", "time" : ISODate("2011-09-05T13:41:57.860Z") }
{ "_id" : 10003, "count" : 3, "news" : "i hava a dream", "time" : ISODate("2011-09-05T13:42:09.794Z") }
{ "_id" : 10004, "count" : 4, "news" : "wow! it is very good!", "time" : ISODate("2011-09-05T13:42:19.185Z") }
{ "_id" : 10005, "count" : 5, "news" : "new a good day", "time" : ISODate("2011-09-05T13:42:36.860Z") }
> db.news.findOne() //select top 1 * from [news]
{ "_id" : 10001, "count" : 1, "news" : "i hava a dream", "time" : ISODate("2011-09-05T13:40:58.034Z") }
> db.news.find({"_id":10001,"count":1}) //select * from [news] where _id=10001 and count=1
{ "_id" : 10001, "count" : 1, "news" : "i hava a dream", "time" : ISODate("2011-09-05T13:40:58.034Z") }
> db.news.find({"count":{"$gt":2,"$lte":4}}) //select * from [news] where count>2 and count stime = new Date()
ISODate("2011-09-05T13:57:21.812Z")
> db.news.find({"time":{"$lt":stime}}) //select * from news where time db.news.find({"count":{"$gt":2,"$lte":4}},{"_id":0,"time":1,"news":1}) // select time,news from [news] where count>2 and count2 and count