Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-41209

Pass $comment operator to change streams

    • Type: Icon: Improvement Improvement
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Usability
    • None
    • Query

      The $comment operator can play a crucial role in tracking activity via logs. It could also be leveraged as a powerful tool if implemented in change streams.

      Right now, the $comment operator is not extracted from update statements for change streams (it's also not in the oplog). Change stream events could include the $comment as part of the event to help pass information from the application to watchers. This could also help remove the need to use the fullDocument by passing important information the client has at update time to the watcher.

      Console 1:

      rs1:PRIMARY> db.change.insertOne({ a: 1 }, { $comment: "xyz"})
      { "acknowledged" : true, "insertedId" : ObjectId("5cdecb71145ee7ea46f4dbbc")}
      rs1:PRIMARY> db.change.updateOne({ a: 1, $comment: "xyz" }, { $set: { b: 1 }})
      { "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 0 }
      

       
      Console 2:

      rs1:PRIMARY> var c = db.change.watch([])
      rs1:PRIMARY> while(!c.isExhausted()) { if(c.hasNext()) { printjson(c.next()); } }
      { "_id" : { "_data" : "825CDECC220000000229295A1004DD3C7BF897AE42EE82E6F9CC8A3C8A3546645F696400645CDECC22145EE7EA46F4DBBE0004" }, "operationType" : "insert", "clusterTime" : Timestamp(1558105122, 2), "fullDocument" : { "_id" : ObjectId("5cdecc22145ee7ea46f4dbbe"), "a" : 1 }, "ns" : { "db" : "test", "coll" : "change" }, "documentKey" : { "_id" : ObjectId("5cdecc22145ee7ea46f4dbbe") }}
      { "_id" : { "_data" : "825CDECC260000000129295A1004DD3C7BF897AE42EE82E6F9CC8A3C8A3546645F696400645CDECC22145EE7EA46F4DBBE0004" }, "operationType" : "update", "clusterTime" : Timestamp(1558105126, 1), "ns" : { "db" : "test", "coll" : "change" }, "documentKey" : { "_id" : ObjectId("5cdecc22145ee7ea46f4dbbe") }, "updateDescription" : { "updatedFields" : { "b" : 1 }, "removedFields" : [ ] }}
      

       

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            justin.labreck@mongodb.com Justin LaBreck
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: