new Mongo() new Mongo(<host>) new Mongo(<host:port>)
得到数据库实例
1
conn = new Mongo() db = conn.getDB("myDatabase") 也可以 db = connect("localhost:27017/myDatabase")
查询数据库数据,更新
1 2 3 4
var id = 123; var temp = db.ttt.findOne({type:id}); if(temp != null){ db.ttt.update({type:id},{$set:{commentId:NumberLong(temp.commentId),type:NumberLong(id)}}); }
数据集合遍历并操作
1 2
db.ttt.find({type:123}).forEach( function(x){ // or other operations print(x); } )