Skip to content

Latest commit

 

History

History
76 lines (52 loc) · 1.9 KB

1-empty-aggregation.mdx

File metadata and controls

76 lines (52 loc) · 1.9 KB

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

👐 Empty Aggregation Pipeline

An empty aggregation

This code is the equivalent of a SELECT * FROM AUTHORS. It returns a cursor with all documents in the authors collection:

  • Make sure Collections > authors is selected.
  • Open the Aggregation tab.
  • Select Text.
  • Notice the empty array in the editor denoting an empty aggregation pipeline:
[]

You're getting all documents in authors (although the Atlas UI is only showing a 10-documents sample)

db.authors.aggregate([])

We can iterate over the returned cursor and get more documents by typing it.

👐 Return all the documents in the books collection and iterate to get the next page of books.

Answer
db.books.aggregate([])
it

🦸‍♂️ Cursor methods

:::info Extra activity! Do it if you have extra time or are following along at home. It won't be covered during the hands-on lab. :::

A cursor has several useful methods. For instance, we can check the size of the returned cursor with itcount.

cursor.itcount()

👐 In our previous example with the empty aggregation, to check the size of the returned cursor, what should we type in?

Answer
// as db.books.aggregate([]) returns a cursor we can just call itcount() on it
db.books.aggregate([]).itcount()