Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-889

ChangeStreamCursor not immediately initialized

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 1.0.1
    • Affects Version/s: None
    • Component/s: Shell API
    • Labels:
      None
    • Not Needed
    • Iteration Geneva

      as reported in #mongosh on Slack:

      replset [primary] test> var changeStream = db.watch()
      ChangeStreamCursor on test
      replset [primary] test> db.foo.insert({name:"John"})
      DeprecationWarning: Collection.insert() is deprecated. Use insertOne, insertMany, or bulkWrite.
      {
        acknowledged: true,
        insertedIds: { '0': ObjectId("60ec1c6464ec76b1492fae72") }
      }
      replset [primary] test> changeStream.next()
      Warning: If there are no documents in the batch, next will block. Use tryNext if you want to check if there are any documents without waiting.
      
      replset:PRIMARY> var changeStream = db.watch()
      replset:PRIMARY> db.foo.insert({name: "foo"})
      WriteResult({ "nInserted" : 1 })
      replset:PRIMARY> changeStream.next()
      {
      	"_id" : {
      		"_data" : "8260EC1C9E000000012B022C0100296E5A1004627EABB2BF0E4DDB8D434E0CB526A8B046645F6964006460EC1C9E42E74AB99614C8460004"
      	},
      	"operationType" : "insert",
      	"clusterTime" : Timestamp(1626086558, 1),
      	"fullDocument" : {
      		"_id" : ObjectId("60ec1c9e42e74ab99614c846"),
      		"name" : "foo"
      	},
      	"ns" : {
      		"db" : "test",
      		"coll" : "foo"
      	},
      	"documentKey" : {
      		"_id" : ObjectId("60ec1c9e42e74ab99614c846")
      	}
      }
      

            Assignee:
            anna.henningsen@mongodb.com Anna Henningsen
            Reporter:
            anna.henningsen@mongodb.com Anna Henningsen
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: