【发布时间】:2014-08-12 18:08:23
【问题描述】:
我是 NodeJS 的新手,我正在使用 MongoJS 连接到我的数据库。
一切正常,但是当我使用 db.collection.find() 函数时,它只返回数据库中的前 10 个结果。
function listMessages(from,to){
console.log("[REQ] User "+from+" asked chat with "+to);
var htext = 'Welcome to the chat<br/>';
db.messages2.find({$or:[{from_id: from, to_id: to}, {from_id: to, to_id: from}]},function(err, echoData) {
if( err || !echoData) console.log("No messages found");
else echoData.forEach( function(returnData) {
htext += returnData.from_id+": "+returnData.text+"<br/>";
});
io.sockets.emit('html message '+from, htext, to);
});
}
它工作正常,但只返回数据库中的前 10 个结果,即使我使用了限制。
我也试过用这个,没用:
db.messages2.find({$or:[{from_id: from, to_id: to}, {from_id: to, to_id: from}]},{},{limit: 50}, function(err, echoData) {
我需要做什么来解决这个问题?谢谢!
【问题讨论】:
标签: javascript node.js mongodb socket.io mongojs