Adding metadata to Change Events

Is it possible to add some metadata to change stream events from the application that updated the document in the database? For example, if I wanted to add some information about the application that made the update for logging/reporting purposes, is there some mechanism to indicate the source of the update without storing this information within each document in the database?

See the example “metadata” field below as an example of what I’m referring to:

{
   "_id": { <Resume Token> },
   "operationType": "update",
   "clusterTime": <Timestamp>,
   "ns": {
      "db": "engineering",
      "coll": "users"
   },
   "documentKey": {
      "_id": ObjectId("58a4eb4a30c75625e00d2820")
   },
   "metadata" : {
      "source": "my_app_1"
    },
   "updateDescription": {
      "updatedFields": {
         "email": "alice@10gen.com"
      },
      "removedFields": ["phoneNumber"],
      "truncatedArrays": [ {
         "field" : "vacation_time",
         "newSize" : 36
      } ]
   },
   "fullDocument": {
      "_id": ObjectId("58a4eb4a30c75625e00d2820"),
      "name": "Alice",
      "userName": "alice123",
      "email": "alice@10gen.com",
      "team": "replication"
   }
}
1 Like

i don’t think the doc mentions such support. so officially, no.

This would be a very cool feature. We could easily implement an audit trail system with just a CDC and some metadata on the session or more precisely on the operation.