Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate return empty #91

Open
uslualper opened this issue Nov 25, 2023 · 0 comments
Open

Aggregate return empty #91

uslualper opened this issue Nov 25, 2023 · 0 comments
Assignees

Comments

@uslualper
Copy link

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 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants