Grokking MongoDB
Vote

0% completed

​

MongoDB Aggregation $count

Ask a pipeline to count the cancelled orders in a collection that has none, and the answer is not zero. The answer is no document at all. The $count stage is simple in most other ways, but this behavior causes real bugs in application code, so the lesson begins with the normal case and then returns to it.

The $count stage produces one document that holds the number of documents reaching it. You choose the name of the output field. The examples in this lesson use five orders from a small fruit shop.

db.orders.drop() db.orders.insertMany([

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content