Skip to content

Commit afd4e72

Browse files
committed
you're doing great
1 parent 5cff102 commit afd4e72

File tree

2 files changed

+21
-40
lines changed

2 files changed

+21
-40
lines changed

046_mongodb/12_aggregate/README.md

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,31 @@ Aggregations operations process data records and return computed results. Aggreg
44

55
[documenation about aggregation](https://docs.mongodb.com/manual/aggregation/)
66

7-
### single purpose aggregation
7+
## single purpose aggregation
88

99
[documenation about single purpose aggregation](https://docs.mongodb.com/manual/aggregation/#single-purpose-agg-operations)
1010

1111
There are two functions you can use:
1212

1313
#### [db.collection.count()](https://docs.mongodb.com/manual/reference/method/db.collection.count/#db.collection.count)
1414

15-
syntax
16-
```
17-
db.collection.count(query, options)
18-
```
19-
20-
| Parameter | Description |
21-
| --- | --- |
22-
| query | The query selection criteria.
23-
| options | Optional. Extra options for modifying the count.
24-
25-
2615
#### [db.collection.distinct()](https://docs.mongodb.com/manual/reference/method/db.collection.distinct/#db.collection.distinct)
2716

28-
syntax
2917
```
3018
db.collection.distinct(field, query, options)
3119
```
3220

33-
3421
| Parameter | Description |
3522
| --- | --- |
3623
| field | The field for which to return distinct values.
3724
| query | A query that specifies the documents from which to retrieve the distinct values.
3825
| options | Optional. A document that specifies the options. See Options.
3926

40-
### examples - count()
27+
#### examples - count()
4128
```
4229
db.oscars.count()
4330
```
4431

45-
The above is equivalent to
46-
4732
```
4833
db.oscars.find().count()
4934
```
@@ -56,7 +41,7 @@ db.customers.find({role:"citizen"}).count()
5641
db.customers.find({$or: [{name:"Bond"}, {age:{$gt:32}}]}).count()
5742
```
5843

59-
### examples - distinct() - setup
44+
#### examples - distinct() - setup
6045
```
6146
db.inventory.insert([
6247
{ "_id": 1, "dept": "A", "item": { "sku": "111", "color": "red" }, "sizes": [ "S", "M" ] },
@@ -66,14 +51,12 @@ db.inventory.insert([
6651
])
6752
```
6853

69-
### examples - distinct()
54+
#### examples - distinct()
7055

7156
```
7257
db.inventory.distinct( "dept" )
7358
```
7459

75-
embedded field:
76-
7760
```
7861
db.inventory.distinct( "item.sku" )
7962
```
@@ -82,19 +65,25 @@ db.inventory.distinct( "item.sku" )
8265
db.inventory.distinct( "sizes" )
8366
```
8467

85-
86-
You use different **expressions** (listed below) in aggregate group operations.
68+
## aggregation pipeline
8769

8870
![aggregate pipeline](aggregate.png)
8971

9072
```
9173
db.<collection name>.aggregate([{<match, sort, geoNear>},{<group>}])
9274
```
9375

94-
[documenation](https://docs.mongodb.com/manual/aggregation/)
95-
[match, sort, geonear](https://docs.mongodb.com/manual/core/aggregation-pipeline/#aggregation-pipeline-operators-and-performance)
76+
MongoDB’s aggregation framework is modeled on the concept of data processing pipelines. Documents enter a multi-stage pipeline that transforms the documents into an aggregated result.
77+
78+
The most basic pipeline stages provide filters that operate like queries and document transformations that modify the form of the output document.
9679

97-
### examples - setup
80+
Other pipeline operations provide tools for grouping and sorting documents by specific field or fields as well as tools for aggregating the contents of arrays, including arrays of documents. In addition, pipeline stages can use operators for tasks such as calculating the average or concatenating a string.
81+
82+
The pipeline provides efficient data aggregation using native operations within MongoDB, and is the preferred method for data aggregation in MongoDB.
83+
84+
[source](https://docs.mongodb.com/manual/aggregation/)
85+
86+
#### example - setup
9887
```
9988
db.orders.insert([
10089
{"cust_id":"A123","amount":500,"status":"A"},
@@ -104,22 +93,10 @@ db.orders.insert([
10493
])
10594
```
10695

107-
### examples
96+
#### example
10897
```
10998
db.orders.aggregate([
11099
{$match:{status:"A"}},
111100
{$group:{_id: "$cust_id",total: {$sum:"$amount"}}}
112101
])
113-
```
114-
115-
116-
### expressions
117-
118-
| expression | description |
119-
120-
```
121-
db.oscars.createIndex({title:1})
122-
db.oscars.createIndex({releaseYear:1, releaseDay:1})
123-
```
124-
125-
[learn to create a unique index and more](https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#db.collection.createIndex)
102+
```
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Learning more about mongo
2+
3+
[relationships, deployment, sharding, replication, and more](https://www.tutorialspoint.com/mongodb/mongodb_relationships.htm)
4+

0 commit comments

Comments
 (0)