Skip to content

Latest commit

 

History

History
74 lines (50 loc) · 1.73 KB

1-empty-aggregation.mdx

File metadata and controls

74 lines (50 loc) · 1.73 KB

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

👐 Empty aggregation pipeline

An empty aggregation

This code is the equivalent to a SELECT * FROM AUTHORS. Returns a cursor with all documents in the authors collection:

  • Open the Aggregation tab.
  • Select Text.
  • Notice the empty array in the editor denoting an empty aggregation pipeline:
[]
db.authors.aggregate([])

We can iterate over the returned cursor and get more documents 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 at home, 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()