Query and Projection Operators
쿼리 연산자 및 프로젝션 연산자
- Query Operator는 DB 내에서 데이터를 검색하는 연산자이고,
Projection Operator는 데이터의 출력 방식을 조작하는 연산자이다.
Query Selectors (쿼리 셀렉터, 쿼리 연산자)
Comparison (비교 연산자)
For comparison of different BSON type values, see the specified BSON comparison order.
| Name | Syntax | Description |
|
{ <field>: { $eq: <value> } }
|
동등 연산 (=)
|
|
| $ne |
{ <field>: { $ne: <value> } }
|
부등 연산 (≠)
|
| $gt |
{ <field>: { $gt: <value> } }
|
초과 연산 (>)
|
| $gte | { <field>: { $gte: <value> } } | 이상 연산 (≥) |
|
{ <field>: { $lt: <value> } }
|
미만 연산 (<)
|
|
|
{ <field>: { $lte: <value> } }
|
이하 연산 (≤)
|
|
| $in |
{ <field>: { $in: [<value1>, <value2>, ... <valueN> ] } }
|
포함 연산 (\(\in\))
|
| $nin |
{ <field>: { $nin: [ <value1>, <value2> ... <valueN> ] } }
|
부정 포함 연산 (\(\notin\)
|
Logical (논리 연산자)
| Name | Syntax | Description |
|
{ $and: [ { <expr1> }, { <expr2> } , ... , { <exprN> } ] }
|
AND 연산
|
|
|
{ <field>: { $not: { <op-expr> } } }
|
NOT 연산
|
|
|
{ $nor: [ { <expr1> }, { <expr2> }, ... { <exprN> } ] }
|
NOR 연산
|
|
|
{ $or: [ { <expr1> }, { <expr2> }, ... , { <exprN> } ] }
|
OR 연산
|
Element (논리 연산자)
| Name | Syntax | Description |
|
{ field: { $exists: } }
|
Matches documents that have the specified field.
|
|
|
{ field: { $type: <BSON type> } }
{ field: { $type: [ <BSON type1> , <BSON type2>, ... ] } } |
Selects documents if a field is of the specified type.
|
Evaluation
| Name | Description |
|
Allows use of aggregation expressions within the query language.
|
|
|
Validate documents against the given JSON Schema.
|
|
|
Performs a modulo operation on the value of a field and selects documents with a specified result.
|
|
|
Selects documents where values match a specified regular expression.
|
|
|
Performs text search.
|
|
|
Matches documents that satisfy a JavaScript expression.
|
Geospatial
| Name | Description |
|
Selects geometries that intersect with a GeoJSON geometry. The 2dsphere index supports $geoIntersects.
|
|
|
Selects geometries within a bounding GeoJSON geometry. The 2dsphere and 2d indexes support $geoWithin.
|
|
|
Returns geospatial objects in proximity to a point on a sphere. Requires a geospatial index. The 2dsphere and 2d indexes support $nearSphere.
|
Array (배열 연산자)
| Name | Description |
|
Matches arrays that contain all elements specified in the query.
|
|
|
Selects documents if element in the array field matches all the specified $elemMatch conditions.
|
|
|
Selects documents if the array field is a specified size.
|
Bitwise (비트 연산자)
| Name | Description |
|
Matches numeric or binary values in which a set of bit positions all have a value of 0.
|
|
|
Matches numeric or binary values in which a set of bit positions all have a value of 1.
|
|
|
Matches numeric or binary values in which any bit from a set of bit positions has a value of 0.
|
|
|
Matches numeric or binary values in which any bit from a set of bit positions has a value of 1.
|
Projection Operators (프로젝션 연산자)
|
Name
|
Description
|
|
Projects the first element in an array that matches the query condition.
|
|
|
Projects the first element in an array that matches the specified $elemMatch condition.
|
|
|
Projects the document's score assigned during $text operation.
|
|
|
Limits the number of elements projected from an array. Supports skip and limit slices.
|
Miscellaneous Operators (기타 연산자)
| Name | Description |
|
Adds a comment to a query predicate.
|
|
|
Generates a random float between 0 and 1.
|
Reference: MongoDB Documentation (URL)
