promised-mongo
promised-mongo copied to clipboard
Tailable Cursor documentation doesn't work
When I try to register "cursor.on" I get an "undefined is not a function" error.
I can set a breakpoint and inspect "cursor" - and there is no "on"; and I can't see how I should receive items.
Since this is promised-mongo, I'm guessing there's a promise callback?
Thanks in advance!
Here's a code snippet to get a feel for what I'm doing:
function setupAlerts(queue) {
debugger;
var cursor = queue.find(
{ // query
},
{}, // projection
{tailable: true, timeout: false}
);
//cursor.on("data", function(data) {
// // send message
// debugger;
//});
}
db.dropCollection("alertsQueue").then(function() {
db.createCollection(
"alertsQueue",
{
capped: true,
size: 4096 * 2,
max: 256,
// awaitdata: true,
timeout: false
}
)
.then(setupAlerts)
.catch(function(err) {
console.error("Something happened with the alerts queue. " + err);
process.exit(1);
});
});
I got something to work, but I'm not sure why it works and how the differences between what I have and what is documented play into it:
function setupAlerts(queue) {
debugger;
queue.save({ placeholder: true }, function () {
var cursor = queue.find(
{ // query
"Year" : {"$gt": 1990}
},
{}, // projection
{ tailable: true, timeout: false }
);
cursor.on("data", function (data) {
// send message
debugger;
console.log("Got Data! ");
});
})
}
debugger;
var aq = db.collection("alertsQueue");
if (aq != null) {
db.dropCollection("alertsQueue").then(function () {
db.createCollection(
"alertsQueue",
{
capped: true,
size: 4096 * 2,
max: 256,
// awaitdata: true,
timeout: false
}
)
.then(function () {
debugger;
setupAlerts(db.collection("alertsQueue"));
console.log("drop attempt over with")
})
.catch(function (err) {
console.error("Something happened with the alerts queue. " + err);
})
;
});
} else {
setupAlerts(aq);
}
Thanks for the detailed report. Sorry I've not been able to reply until now. I'll look into this.
This should work in the latest version - can you give it a go and get back to me?