Nosql Mongodb之旅(8)—MongoDB高级查询の游标使用

前端之家收集整理的这篇文章主要介绍了Nosql Mongodb之旅(8)—MongoDB高级查询の游标使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。


像大多数数据库产品一样,MongoDB 也是用游标来循环处理每一条结果数据,具体语法如

下:

  1. >for(varc=db.t3.find();c.hasNext();){
  2. printjson(c.next());
  3. }
  4. {"_id":ObjectId("4fb8e4838b2cb86417c9423a"),"age":1}
  5. {"_id":ObjectId("4fb8e4878b2cb86417c9423b"),"age":2}
  6. {"_id":ObjectId("4fb8e4898b2cb86417c9423c"),"age":3}
  7. {"_id":ObjectId("4fb8e48c8b2cb86417c9423d"),"age":4}
  8. {"_id":ObjectId("4fb8e48e8b2cb86417c9423e"),"age":5}

MongoDB 还有另一种方式来处理游标


  1. >db.t3.find().forEach(function(u){printjson(u);});
  2. {"_id":ObjectId("4fb8e4838b2cb86417c9423a"),"age":1}
  3. {"_id":ObjectId("4fb8e4878b2cb86417c9423b"),"age":2}
  4. {"_id":ObjectId("4fb8e4898b2cb86417c9423c"),"age":3}
  5. {"_id":ObjectId("4fb8e48c8b2cb86417c9423d"),"age":4}
  6. {"_id":ObjectId("4fb8e48e8b2cb86417c9423e"),"age":5}
  7. >

猜你在找的NoSQL相关文章