In this exercise, you’ll add two processing options to the aggregate statement after the pipeline. Processing options make it possible to control how the aggregation is executed.
To add processing options to the aggregation
- On the IntelliShell tab, ensure that the aggregate statement you updated in the previous exercise is still entered at the command prompt.
- After the pipeline’s closing bracket, type a comma and insert a new line.
- On the new line after the pipeline, add the following options to the statement (before the aggregate method’s closing parenthesis):
{ "allowDiskUse": true, "collation": { "locale": "en_US" } }
This code adds two options to the aggregate statement:
- When set to
true
, theallowDiskUse
option enables the aggregation operations to write to temporary files, which can be useful with large data sets. - The second option is
collation
, which specifies the collation to use for the aggregation. In this case, the collation is US English.
The final aggregate statement should now look like the following code:
db.customers.aggregate( [ { "$match": { "dob": { "$lt": ISODate("1970-01-01T00:00:00.000Z") } } }, { "$group": { "_id": "$address.state", "total": { "$sum": "$transactions" } } }, { "$sort": { "total": -1 } } ], { "allowDiskUse": true, "collation": { "locale": "en_US" } } );
- On the IntelliShell toolbar, click the Execute button. Studio 3T runs the aggregate statement and displays the results in the lower pane. The results are the same as those in the previous exercise.
- On the IntelliShell toolbar, click the Save button. This will allow you to save the aggregate statement to a script file with the .js extension. You’ll use this file in the next section of this course.
- In the Save Script dialog box, name the file state_transactions.js, navigate to a target folder, and click Save.
- Close the IntelliShell tab, and then close Studio 3T.