From what I saw in the example the _id
does not have a link:
If you have a bond you can make one lookup in Collection Usuario
in place in the project, I did on top of the result you put as an example
You can do it like this:
db.login.aggregate([
{
$match: {
'Login': 'admin',
'Senha': '12345',
}
},
{
$project :{
login: db.login.distinct('Usuarios.Login', { 'Usuarios.Login': 'andre' }),
senha: db.login.distinct('Usuarios.Senha', { 'Usuarios.Login': 'andre' }),
}
},
{ $unwind: { 'path': '$login', 'preserveNullAndEmptyArrays': false } },
{ $unwind: { 'path': '$senha', 'preserveNullAndEmptyArrays': false } },
{
$match: {
'login': 'andre',
'senha': '17344',
}
}
])
If you can post subdocuments, it’s better to help.
– jcardoso