From 3dd11974ca2c671b717010bbc6e4fd401f14dd3c Mon Sep 17 00:00:00 2001 From: David Fu Date: Tue, 9 Aug 2022 14:00:13 +0800 Subject: [PATCH] fix(condition): update document must contain key beginning with '$' --- mtest/collection.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mtest/collection.go b/mtest/collection.go index 04372aa..d29559c 100644 --- a/mtest/collection.go +++ b/mtest/collection.go @@ -118,7 +118,7 @@ func (r *Assert) Empty() *Assert { func conditionExists(t *testing.T, col *mongo.Collection, documents ...interface{}) { for _, document := range documents { - _, err := col.UpdateOne(context.TODO(), document, options.Update().SetUpsert(true)) + _, err := col.UpdateOne(context.TODO(), document, bson.M{"$set": document}, options.Update().SetUpsert(true)) if err != nil { t.Fatalf("can not ensure document [%#v] in collection [%v]: %v", document, col.Name(), err) }