Вот мои структуры
type Result struct {
User primitive.ObjectID `json:"user" bson:"user"`
Test primitive.ObjectID `json:"test" bson:"test,omitempty"`
Answers []Answers `json:"answers" bson:"answers"`
}
type Test struct {
Id primitive.ObjectID `json:"id" bson:"_id,omitempty" db:"_id"`
Title string `json:"title" bson:"title" db:"title" binding:"required"`
Tasks []Task `json:"tasks" bson:"tasks" db:"tasks" binding:"required"`
}
Я делаю такой запрос и мне выдает ошибку
error decoding key test: cannot decode array into an ObjectID
matchStage := bson.D{{"$match", bson.D{{"user", objectID}}}}
lookupStage := bson.D{{
"$lookup", bson.D{
{"from", "tests"},
{"localField", "test"},
{"foreignField", "_id"},
{"as", "test"},
}},
}
cursor, err := r.db.Aggregate(nil, mongo.Pipeline{matchStage, lookupStage})