我試圖從node.js的/ MongoDB實例「流」數據使用WebSockets的客戶端。這一切都運作良好。確定最後文件從MongoDB中找到()結果集
但如何我確定結果的最後一個文件?我使用node-mongodb-native從node.js中連接到MongoDB的
一個簡單的例子:
collection.find({}, {}, function(err, cursor) {
if (err) sys.puts(err.message);
cursor.each(function(err, doc) {
client.send(doc);
});
});
這可能不是以流從DB-e.g文檔的最佳方法。如果文檔插入的速度比以這種方式查詢速度快?請參閱http://docs.mongodb.org/manual/tutorial/create-tailable-cursor/ – 2014-02-03 23:16:53