Vous pouvez essayer l'agrégation ci-dessous.
Étapes $match - $graphLookup - $project
.
$reduce
pour choisir le premier élément de chacun des $graphLookup
nameList's
na
tableau.
db.taxon.aggregate([{
$match: {
_id: {
$in: listId
}
}
}, {
$graphLookup: {
from: "taxon",
startWith: "$_id",
connectFromField: "pa",
connectToField: "_id",
as: "nameList"
}
}, {
$project: {
nameList: {
$reduce: {
input: "$nameList",
initialValue: [],
in: {
"$concatArrays": ["$$value", {
$slice: ["$$this.na", 1]
}]
}
}
}
}
}])