mongoDB operators - Expressive, Array Query Operators, Projection, Dot notation
$
$->フィールドの値にアクセスできます.
$expr-> expressive Query operator. 同じドキュメント内の異なるフィールドの値を比較できます.
db.trips.find({
"$expr": {
"$eq": [ "$start station id", "$end satation id" ]
}
})
値がstart station id
のフィールドと値がend station id
のドキュメントを検索します.db.trips.find({
"$expr": {
"$and": [
{"$gt": ["$trip duration", 1200]},
{"$eq": ["$start station id", "$end station id"]}
]
}
})
trip duration
フィールドの値が1200より大きい場合、start station id
フィールドの値はend station id
フィールドの値と同じである.Array operators
db.air_bnb.find({ amenities: "shampoo" }) => 샴푸가 들어간 amenities를 가진 document 반환
db.air_bnb.find({ amenities: ["shampoo"] }) => amenities: ["shampoo"] 인 document 반환
arrayを値とするフィールドでは、array要素の順序もドキュメントの検索に影響します.順序が影響を受けないようにするには、$allという演算子を使用する必要があります.
db.air_bnb.find({ amenities: { "$all": ["shampoo"] } }) => amenities array에 shampoo가 포함된 모든 document 반환
db.air_bnb.find({ amenities: { "$size": 20, "$all": ["shampoo"] } }) => amenities array에 shampoo가 포함된 모든 document들 중 amenities의 갯수가 20개인 document만 반환
$elemMatch
配列内の要素にアクセスします.
"$elemMatch": { <field>: <value> }
db.grades.find({ "class_id": 431 },
{ "scores": { "$elemMatch": { "score": { "$gt": 85 } } }
}).pretty()
projection
projection -> Specifies which fields should or should not be included in the result cursor.
結果に返されるdocumentの表示フィールドまたは非表示フィールドをソートします.0->非表示、1->非表示.0と1は併用できません.しかしidについては0を混用することができる.
dotNotation [.]
documentフィールドのサブフィールドにアクセスするか、配列形式フィールドのn番目のフィールドにアクセスします.
Reference
この問題について(mongoDB operators - Expressive, Array Query Operators, Projection, Dot notation), 我々は、より多くの情報をここで見つけました https://velog.io/@sunnysideup0w0/mongoDB-operators-Expressive-Array-Query-Operatorsテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol