Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-919

add JavaScript TailableCursor example

    XMLWordPrintableJSON

Details

    • Icon: Task Task
    • Resolution: Won't Fix
    • Icon: Major - P3 Major - P3
    • v1.1
    • None
    • None
    • None

    Description

      This example kind of works but is missing the handling of a dead cursor:

      var coll = db.myCappedCollection;
      var startDoc = coll.find().hint(

      { '$natural': 1 }

      ).limit(1).next();
      var lastValue = startDoc['insertDate'];
      printjson(startDoc)
      var cursor = coll.find( { 'insertDate' :

      { '$gt' : lastValue }

      }
      ).hint(

      { '$natural': 1 }

      ).addOption( DBQuery.Option.tailable ).addOption( DBQuery.Option.awaitData );

      while (1) {
      try {
      if ( cursor.hasNext() )

      { var doc = cursor.next(); lastValue = doc['insertDate']; printjson(doc); }

      } catch (e)

      { break; }

      }

      Attachments

        Activity

          People

            kay.kim@mongodb.com Kay Kim (Inactive)
            kay.kim@mongodb.com Kay Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              11 years, 1 week ago