I have this two example of collection:
Collection 1
_id : 5fa2bf16987ad021094dbf6f,
date : 2020-11-05T08:18:00.000+00:00,
idTwo : 5f9925c095b8a429083fb45d,
prest : 2
Collection 2
_id : 5f9925c095b8a429083fb45d,
idAgenda : [
{
id : 1,
price: 122,
enable : true,
label : "label 1"
},{
id : 2,
price: 25,
enable : true,
label : "label 2"
},{
id : 3,
price: 149,
enable : true,
label : "label 3"
}],
Surname: "Surname",
Name: "Name
from _id of collection 1, I would like to merge collection 1 with collection 2
where idTwo of collection1 is = _id of collection2
and idAgenda of collection 2 is = prest of collection 1
I suppose that I need pipeline (for $unwind for example idAgenda), but I don’ t understand how use it.
I have try with this $lookup:
{
from: 'Collection2',
localField: 'idTwo',
foreignField: '_id',
as: 'string'
}
But in **string ** I have an array with all collection2…I need only the Collection2.idAgenda can match with Collection1.prest.
Do you have suggestion for me?