是否可以使用find并发出所有参数来选择插入到mongoDB中的最后30条记录或任何数量的记录。
db.tweets.find({}, function(err, docs){
response.end(JSON.stringify(docs));
});
我不确定大括号中需要包含什么内容。
mongo-native的find()语法(与mongoskin相同)是:
find(query[, options], callback)
要么
find(query[, options]).toArray(callback)
第一个参数是搜索条件,因此它不能在其中,但可以在可选的第二个参数中添加限制。像这样:
db.tweets.find({}, {limit: 30}).toArray(function(err, docs){
response.end(JSON.stringify(docs));
});
更新:您还可以指定'sort'来获取LAST30。类似这样的内容:{limit:30,sort:[“ timestamp”,“ desc”]}(“ desc”或-1,不记得语法),其中“时间戳”是您要排序的字段。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句