I have an array of ObjectIds in my MongoDB documents and I'd like to use Go (specifically mgo.v2) to perform a query that populates them with data from the documents that they reference. For example:
{
_id: ObjectId("some_id"),
events: [
ObjectId("referenced_id_1"),
ObjectId("referenced_id_2")
]
}
I'd like the query to return the documents in the following format:
{
_id: ObjectId("some_id"),
events: [
{
_id: ObjectId("referenced_id_1"),
name: "some_name_1"
},
{
_id: ObjectId("referenced_id_2"),
name: "some_name_2"
}
]
}
As far as I can tell I'd need to use $lookup and then $unwind, but can't seem to figure it out. Any help would be very much appreciated! Thanks :)
.populate('event', 'name')... so I was hoping there was an equivalent in mgo.v2 for Go. If not then yes, I will have to do multiple queries.