[SERVER-41209] Pass $comment operator to change streams Created: 17/May/19  Updated: 06/Dec/22  Resolved: 03/Jun/19

Status: Closed
Project: Core Server
Component/s: Usability
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Justin LaBreck Assignee: Backlog - Query Team (Inactive)
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Query
Participants:

 Description   

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" : [ ] }}

 



 Comments   
Comment by Craig Homa [ 03/Jun/19 ]

The comments are not meant to be persisted as data, instead, a good workaround is to store the comment in the data itself.

Generated at Thu Feb 08 04:57:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.