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); });