I have been facing some difficulties with $lookup:
My struct:
type Item struct {
ID bson.ObjectId `json:"id" bson:"_id"`
Name string `json:"name" bson:"name"`
Description string `json:"description" bson:"description"`
CoverImage bson.ObjectId `json:"cover_image,omitempty" bson:"cover_image,omitempty"`
GalleryList []*File
}
pipeline := []bson.M{
bson.M{
"$lookup": bson.M{
"from": "files",
"localField": "cover_image",
"foreignField": "_id",
"as": "gallerylist",
},
}
So, what I want to do is use $lookup to get structs with matching ID on collection "files" with the "cover_image" field ID.
Until here it's ok, the problem is:
If 'bson:"-"'
is on GalleryList, the pipeline don't unmarshall on the field
Ex: GalleryList []*File 'bson:"-"'
And I don't want GalleryList to be stored inside mongo.
Is there anything that I can to GalleryList don't be inserted with the rest of the struct.
Does I really need to remove this on the frontend or remove manually before inserting on mongo?
Thanks!