promised-mongo icon indicating copy to clipboard operation
promised-mongo copied to clipboard

Tailable Cursor documentation doesn't work

Open Earl-Brown opened this issue 10 years ago • 4 comments

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!

Earl-Brown avatar Feb 04 '15 20:02 Earl-Brown

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);
  });
});

Earl-Brown avatar Feb 04 '15 20:02 Earl-Brown

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);
}

Earl-Brown avatar Feb 05 '15 18:02 Earl-Brown

Thanks for the detailed report. Sorry I've not been able to reply until now. I'll look into this.

gordonmleigh avatar Jun 16 '15 14:06 gordonmleigh

This should work in the latest version - can you give it a go and get back to me?

gordonmleigh avatar Jun 24 '15 14:06 gordonmleigh