컴퓨터언어/Database

[MongoDB University] 정리

bbanpro 2021. 2. 1. 06:55
728x90
반응형

 

파이프라인 : $match(일치모양골라내기) -> $project(형태변형) -> $group(단일파일로만들어전체에대한비율계산)

  • Stages cannot be configured to produce our desired output.

This is definitely not correct. Stages can be configured in almost any way we desire.

 

  • Pipelines must consist of at least two stages.

This is not correct. Pipelines must consist of at least one stage, and can have many stages.

 

  • Documents flow through the pipeline, passing one stage to the next

This is correct.

 

  • The Aggregation Framework provides us many stages to filter and transform our data.

This is also correct.

 

파이프라인은 최소 1개 이상의 stage로 이루어진 배열이다.

각 stage는 최소 1개 이상의 집산 연산자 또는 식으로 구성되어 있다(식 자체도 단 하나의 식이거나 여러 식의 배열로 이루어질 수 있음).

 

In this quiz, we have the following correct answers:

 

  • An aggregation pipeline is an array of stages.

This is correct.

 

  • Some expressions can only be used in certian stages.

This is correct. For example, accumulator expressions can only be used within the $group stage, with select accumulator expressions available in the $project stage. You'll learn about these stages in depth in the course!

The other option is incorrect:

 

  • Only one expression per stage can be used.

This is not correct. Multiple expressions can be used.

 

$match는 여러번 사용될 수 있으며, 특정 예외를 제외하고 다른 연산들이 뒤에 줄지어 온다.

$match는 특정 모양을 골라내는 필터라고 생각하면 된다.

$match는 MongoDB Read 표준 쿼리 연산자를 사용한다. 즉, $match는 $find와 결과가 같다는 것이다.

하지만 $match는 $find에 비해 필터로서 의미가 강하다. 새로운 형태의 field나 data로 가공한다면 $match를 사용한다.

// "Star" 타입이 아닌 것들만 골라내는 것. 두 쿼리의 결과는 같다.

db.solarSystem.aggregate([{ $match: { type: { $ne: "Star" } } }]).pretty()

db.solarSystem.find({ type: { $ne: "Star" } }).pretty()

단, $where를 사용할 수 없으며, $text를 사용한다면 $match 연산자는 pipeline 내에서 반드시 가장 앞에 위치해야 한다.

$match가 pipeline의 가장 앞에 위치한다면, index로서 쿼리를 빠르게 수행한다는 장점을 갖는다.

$match는 pipeline 내에서 앞쪽에 위치해야 한다.

 

db.solarSystem.aggregate([{ $match: { type: { $ne: "Star" } } }, { $count: "planets" }]) // { "planets" : 8 }

db.solarSystem.count({ type: { $ne: "Star" } }) // 8

 

$match는 아래 $find와 달리 projection을 위한 어떤 과정을 일절 포함하지 않는다.

db.solarSystem.find({ name: "Earth" }, { _id: 0 })

 

꼭 기억할 것

The correct answers are:

  • It uses the familiar MongoDB query language.

$match uses the MongoDB query language query operators to express queries.

  • It should come very early in an aggregation pipeline.

The earlier in the pipeline, the more efficient our pipelines will become. Not only because we will expression filters that reduce the number of documents to process, but also the fact that we might be using indexes withing the pipeline execution.

The remaining options are not correct.

$match can use both query operators and aggregation expressions.

$match can only filter documents on one field.

 

728x90
반응형