|
Hi sumit.tembe,
First of all, I believe that you're meaning to specify current v0.2.0 instead of v0.0.2. The below answer would be based on current beta v0.2.0.
I could only replicate error that you have reported above, only if there is no matching documents to update. For example, the below snippet should work:
var filter = bson.D{{"item", "exist"}}
|
var update = bson.D{{"$set", bson.D{{"updated", "true"}}}}
|
result := collection.FindOneAndUpdate(context.TODO(), filter, update)
|
r, err := result.DecodeBytes()
|
While the below snippet, would return err during DecodeBytes():
var filter = bson.D{{"item", "DoesNotExist"}}
|
var update = bson.D{{"$set", bson.D{{"updated", "true"}}}}
|
result := collection.FindOneAndUpdate(context.TODO(), filter, update)
|
r, err := result.DecodeBytes()
|
This is because if there is no document matching the filter to be updated, SingleResult returns null. This is in line with the behaviour of findOneAndUpdate in mongo shell as well.
See also SingleResult.DecodeBytes for more information.
Regards,
Wan.
|