aggregateを使用 :
db.companies.aggregate([
{ $match: { "founded_year":2004 } },
{ $project: { founded_year:1,
moreThanFive: { $gt: [ {$size: "$external_links" }, 5 ] } } },
{ $match: { moreThanFive : true }} ,
])
次のことを行う必要があります。
1。 $projectを含める ステージ、投資の数(size)を見つける アレイの)、5より大きいかどうかを確認します。
2。次に、別の$matchを実行します moreThanFiveでそれらをフィルタリングするステージ trueに等しい 。
findを使用 :
db.companies.find({'investments.5': {$exists: true}})
investmentsのポジション番号6かどうかを尋ねます アレイが存在します。