This is golang. My problem is in the collection search by IDs
I want to find several collections with an array of IDs
This is the document
/*document with name brands*/
{
first_id : "100"
second_id : "200"
name : "adidas",
description: "clothing"
}
{
first_id : "101"
second_id : "202"
name : "ferrari",
description: "auto"
}
This is the collection model
type Brand struct {
FirstID string `bson:"first_id" json:"first_id"`
SecondID string `bson:"second_id" json:"second_id"`
Name *string `bson:"name" json:"name"`
Description *string `bson:"description" json:"description"`
}
This function performs the search by IDs, here is the problem
func searchByID(collection *mongo.Collection) {
ids := [][]string{{"100", "200"}, {"101", "202"}}
filter2 := bson.M{"first_id,second_id": ids} // This is the problem
cursor, err := collection.Find(context.Background(), filter2)
brands := []Brand{}
if err == nil {
for cursor.Next(context.Background()) {
brand := Brand{}
cursor.Decode(&brand)
brands = append(brands, brand)
}
} else {
print(err.Error())
}
print("print the brands")
print(brands) //Result []
}