Open
Description
I want to do what you see using the mgm library, but I couldn't figure it out.
[{
'$unwind': {
'path': '$nodes',
'includeArrayIndex': 'arrayIndex',
'preserveNullAndEmptyArrays': True
}
}, {
'$lookup': {
'from': 'documents',
'localField': 'nodes.data.video',
'foreignField': '_id',
'as': 'results'
}
}, {
'$match': {
'_id': ObjectId('6560f9e87c9e42e241e29c62')
}
}]
func (w *Widget) Get(id string) (interface{}, error) {
widget := &mongodb.Widget{}
documentCollName := mgm.Coll(&mongodb.Document{}).Name()
if cur, err := mgm.Coll(widget).Aggregate(mgm.Ctx(), bson.A{
bson.M{operator.Match: bson.M{field.ID: id}},// If I add this, no result is returned
builder.S(builder.Unwind("$nodes", "arrayIndex", true)),
builder.S(builder.Lookup(documentCollName, "nodes.data.video", "_id", "documents")),
}); err == nil {
results := []bson.M{}
cur.All(mgm.Ctx(), &results)
return results, nil
} else {
fmt.Println(err)
}
return widget, nil }
Metadata
Assignees
Labels
No labels
Activity