I have a dataset in which i want to put lookup inside an id
that is inside an array of objects . now when i add lookup . it replaces the complete document with the lookup result . Now inside that object i have some other content which i want to access, but it gets replaced. Also i dont want to put lookup
in all elements of that array of objects just the first one. The main this is i want to access scale
after the lookup is done
Below is my data-set
"user_id" : ObjectId("5b17b992c440782b5a218cd2"),
"commission" : [
{
"commissson_id" : ObjectId("5bc05984b49e14243f2973ad"),
"scale" : "14"
},
{
"commissson_id" : ObjectId("5bc05992b49e14243f2973ae"),
"scale" : "14"
},
{
"commissson_id" : ObjectId("5bc05984b49e14243f2973ad"),
"scale" : "1"
},
{
"commissson_id" : ObjectId("5bc0596a414d30243f94b0de"),
"scale" : "1"
}
]
So far i have tried this
$pipe=[
[
'$match'=>
[
'_id'=> $user_id
],
],
[
'$lookup'=>
[
'from'=>'commission',
'localField'=>'commission.0.commissson_id',
'foreignField'=> '_id',
'as'=> 'commission'
]
],
];
Aucun commentaire:
Enregistrer un commentaire