Details
Description
When searching for objects using $in, the cursor always drops the first found object. All subsequent displays are normal.
ids := []string{"1","2","3"} |
filter := bson.M{"terminal_id": bson.M{"$in": ids}} |
cursor, err := s.db.Collection(collectionTerminal).Find(ctx, filter)
|
if err != nil { |
return nil, err |
}
|
defer cursor.Close(ctx)
|
|
|
var terminalList []*terminal.Terminal
|
for cursor.Next(ctx) { |
var term *terminal.Terminal
|
err := cursor.Decode(&term)
|
if err != nil { |
fmt.Println(err)
|
return nil, err |
}
|
terminalList = append(terminalList, term)
|
}
|
// in terminalList: [{"id":"2"}, {"id":"3"}]
|
// must be: [{"id":"1"}, {"id":"2"}, {"id":"3"}] |