Con aggregate
:
db.companies.aggregate([
{ $match: { "founded_year":2004 } },
{ $project: { founded_year:1,
moreThanFive: { $gt: [ {$size: "$external_links" }, 5 ] } } },
{ $match: { moreThanFive : true }} ,
])
Deberá:
1. Incluir un $project
etapa, para encontrar el número de inversión (el size
de la matriz), y compruebe si es mayor que 5.
2. y luego haz otro $match
escenario para filtrar aquellos con moreThanFive
es igual a true
.
Con find
:
db.companies.find({'investments.5': {$exists: true}})
Preguntas si la posición número 6 en las investments
matriz existe.