π 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:
- Atlas UI
- MongoDB Shell
- 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()