I am using the Change Streams with Document Pre- and Post-Images which allows us to output a document before and after changes. Here is my sample code in Go:
result := dbClient.Database("admin").
RunCommand(ctx, bson.M{"setFeatureCompatibilityVersion": "6.0"})
if result.Err() != nil {
fmt.Println(result.Err())
}
....
collOpts := options.CreateCollection().
SetChangeStreamPreAndPostImages(bson.M{"enabled": true})
err := db.CreateCollection(ctx, collLog, collOpts)
if err != nil {
logger.Error(err, fmt.Sprintf("failed to set up an additional "+
"collection options"))
}
....
_, err = dbHandler.Collection(collLog).InsertOne(ctx, change)
The result is no difference between Mongo 5 and 6 because it does not show the previous value in the result. Can anyone please help?
My go version is go1.17.13, GO drive 1.11.1 and my MongoDB edition is 6.0.3 Community. Any input will be very helpful.
Thanks.
Please also close my previous topic regarding “About using the changeStreamPreAndPostImages in Mongo 6.0” since I could not change the title after post. Sorry for the inconvenience. Appreciated.
The value of NewFields.suite has been updated from “456” to “1001” in the UpdateFields, but it shows “1001” only. There is NO previous value (i.e., the “456”) in the record.
In an update stream event, the fullDocumentBeforeChange field is missing, even with changeStreamPreAndPostImages set to true. An update event stream only contains the following fields: