Handle both bson.D and bson.M on Find results

This commit is contained in:
George Suntres
2026-04-20 13:08:13 -04:00
parent 29144f54bd
commit 1547f8c736
4 changed files with 24 additions and 11 deletions

View File

@@ -15,7 +15,9 @@ func TestFind_Default(t *testing.T) {
client := GetMongoClient()
filter := bson.M{"name": bson.M{"$regex": "OSRAM"}}
findResult, err := client.Find(context.Background(), "mydb", "mycollection", filter, 0)
findResult, err := client.Find(context.Background(), "mydb", "mycollection", filter, &FindOptions{
Offset: int64(0),
})
if err != nil {
t.Fatalf("Failed to insertOne %#v", err)
}
@@ -74,6 +76,7 @@ func TestFind_Discriminator(t *testing.T) {
client := GetMongoClient()
client.AddDefinition(store)
client.AddDefinition(offer)
// Save two offers with the similar name in different stores each.
@@ -97,7 +100,9 @@ func TestFind_Discriminator(t *testing.T) {
// Now searching in store str_1234 for OSRAM should return only one
filter := bson.M{"name": bson.M{"$regex": "OSRAM*"}}
findResult, err := client.Find(ctx1, "mydb", "offer", filter, 0)
findResult, err := client.Find(ctx1, "mydb", "offer", filter, &FindOptions{
Offset: int64(0),
})
if err != nil { t.Fatalf("Failed to find %#v", err) }
dataAny, hasData := findResult["data"]