Database Reference
In-Depth Information
This command aggregates documents from the
events
collection with a pipeline that:
Uses the
$match
operation to limit the documents that the aggregation framework
must process.
$match
is similar to a
find()
query. This operation selects all doc-
uments where the value of the
time
field represents a date that is on or after (i.e.,
$gte
)
2000-10-10
but before (i.e.,
$lt
)
2000-10-11
.
Uses the
$project
operator to limit the data that continues through the pipeline.
This operator:
▪ Selects the
path
field.
▪ Creates a
y
field to hold the year, computed from the
time
field in the original
documents.
▪ Creates an
m
field to hold the month, computed from the
time
field in the ori-
ginal documents.
▪ Creates a
d
field to hold the day, computed from the
time
field in the original
documents.
Uses the
$group
operator to create new computed documents. This step will create
a single new document for each unique path/date combination. The documents take
the following form:
▪ The
_id
field holds a subdocument with the content's
path
field from the ori-
ginal documents in the
p
field, with the
date
fields from the
$project
as the
remaining fields.
▪ The
hits
field uses the
$sum
statement to increment a counter for every docu-
ment in the group. In the aggregation output, this field holds the total number
of documents at the beginning of the aggregation pipeline with this unique date
and path.