分类: Oracle
2012-06-20 22:01:27
象大多数数据库产品一样,MongoDB也是用游标来循环处理每一条结果数据,具体语法如下:
> for( var c = db.t3.find(); c.hasNext(); ) { ... printjson( c.next()); ... } { "_id" : ObjectId("4fb8e4838b2cb86417c9423a"), "age" : 1 } { "_id" : ObjectId("4fb8e4878b2cb86417c9423b"), "age" : 2 } { "_id" : ObjectId("4fb8e4898b2cb86417c9423c"), "age" : 3 } { "_id" : ObjectId("4fb8e48c8b2cb86417c9423d"), "age" : 4 } { "_id" : ObjectId("4fb8e48e8b2cb86417c9423e"), "age" : 5 } |
MongoDB还有另一种方式来处理游标
> db.t3.find().forEach( function(u) { printjson(u); } ); { "_id" : ObjectId("4fb8e4838b2cb86417c9423a"), "age" : 1 } { "_id" : ObjectId("4fb8e4878b2cb86417c9423b"), "age" : 2 } { "_id" : ObjectId("4fb8e4898b2cb86417c9423c"), "age" : 3 } { "_id" : ObjectId("4fb8e48c8b2cb86417c9423d"), "age" : 4 } { "_id" : ObjectId("4fb8e48e8b2cb86417c9423e"), "age" : 5 } > |