I am attempting to stream some data from a MongoDB capped collection as follows:
var query = {};
var options = {tailable: true, awaitdata: true, numberOfRetries: Number.MAX_VALUE};
var stream = myColl.find(query, options).stream();
stream.on('data', function(doc){
console.log(doc);
}).on('error', function (error){
console.log(error);
}).on('close', function () {
console.log('closed');
});
This prints the documents as expected but upon reaching the end of the collection the stream closes. Is it possible to prevent this from happening? I am looking to have the program print the data as it arrives in the collection, waiting at the end of the collection indefinitely for more data.
答案 0 :(得分:1)
解决了这个问题。结果我的问题是我没有正确格式化我的选项。
myColl.find().tailable(true, { awaitdata: true ,numberOfRetries: Number.MAX_VALUE}).stream();
是正确的,并按预期工作。