1 回答

TA貢獻(xiàn)1821條經(jīng)驗 獲得超6個贊
MongoDB 管道中的每個元素都必須是單個階段,例如$match,$group等。
您的group元素包含 2 個階段:$lookup和$graphLookup.
拆分它們并單獨列出它們:
match := bson.D{{"$match", bson.D{{"venue", venueID}}}}
group := bson.D{{"$lookup", bson.M{
"from": "labels",
"localField": "label_ids",
"foreignField": "_id",
"as": "labels",
}}}
graphLookup := bson.D{{"$graphLookup", bson.M{
"from": "menus",
"startWith": "$child_ids",
"connectFromField": "child_ids",
"connectToField": "_id",
"as": "children",
"maxDepth": 5,
"depthField": "level",
}}}
cur, err := m.collection.Aggregate(ctx, mongo.Pipeline{group, graphLookup, match})
- 1 回答
- 0 關(guān)注
- 186 瀏覽
添加回答
舉報