首页 > 数据库 > MongoDB > 正文

mongodb数据库游标的使用浅析

2020-10-29 18:54:03
字体:
来源:转载
供稿:网友

mongodb中的游标使用示例如下:
 
假设执行如下操作:

db.XXX.remove();db.XXX.insert({"name":"BuleRiver1", "age":27});db.XXX.insert({"name":"BuleRiver2", "age":23});db.XXX.insert({"name":"BuleRiver3", "age":21});

使用find()返回一个游标:

var cursor = db.XXX.find();while (cursor.hasNext()) {  obj = cursor.next();  print(obj.name);}

使用游标的forEach()循环遍历:

cursor.forEach(function(x) {  print(x.name);});
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表