Skip to main content

πŸ¦Έβ€β™‚οΈ Aggregation options

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.

danger

The following syntax doesn't work in the Atlas UI aggregations editor. The editor doesn't support declaring variables. You can try this using the built-in MongoDB Shell in MongoDB Compass.

We can pass a document to aggregate with some options.

let options = {
maxTimeMS: 100
};

db.authors.aggregate([], options);

πŸ’» Have a look at the different options you can pass to the aggregate method.

πŸ’» Try to launch an itcount (a long operation) to iterate through the whole books cursor with a time limit of 10 ms. You should see the operation timing out and failing.

let options = {
maxTimeMS: 10
};

db.authors.aggregate([], options).itcount();

> MongoServerError: operation exceeded time limit