-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Practical MongoDB Aggregations
By :

You probably have a preferred tool for prototyping aggregation pipelines, having already explored the MongoDB aggregation framework before reaching for this book. However, suppose you are looking for alternatives. In that case, in the following section, you will find suggestions to get a MongoDB database and client tool up and running, ready to execute the example aggregations presented in this book.
To develop aggregation pipelines effectively, and to try the examples in Part 2: Aggregations by Example, you will need:
Note
In Part 2: Aggregations by Example, most example aggregation pipelines are compatible with MongoDB version 4.2 and above. However, some examples utilize aggregation features introduced after version 4.2. For these, the book specifies the minimum MongoDB version required.
The MongoDB database deployment for you to connect to can be a single server, a replica set, or a sharded cluster. You can run this deployment locally on your workstation, remotely on-premises, or in the cloud. You will need the MongoDB URL to connect to the database and, if authentication is enabled, the credentials required for full read and write access.
If you don't have access to a MongoDB database, the two most accessible options for running a database are as follows:
Note
Aggregation pipelines in Chapter 13, Full-Text Search Examples, use Atlas Search. Consequently, you must use Atlas for your database deployment if you want to run the few Atlas Search-based examples.
There are various options for the client tool, some of which are:
All examples in this book present code that is easy to copy and paste into MongoDB Shell, i.e., mongosh
, to execute. All subsequent instructions in this book assume you are using the shell. However, you will find it straightforward to use one of the mentioned GUI tools instead, to execute the code examples.
Here is how you can connect MongoDB Shell to an Atlas free-tier MongoDB cluster:
mongosh "mongodb+srv://mycluster.a123b.mongodb.net/test" --username myuser
Before running the command, ensure:
Connect
button in the Atlas console)Here is the command for starting MongoDB Shell and connecting it to a MongoDB single-server database if you've installed MongoDB locally on your workstation:
mongosh "mongodb://localhost:27017"
By using the MongoDB Playground tool in VS Code, you can quickly prototype queries and aggregation pipelines and execute them against a MongoDB database with the results shown in an output tab. Figure 1.3 shows the Playground tool in action:
Figure 1.3: MongoDB Playground tool in Microsoft Visual Studio Code
MongoDB Compass provides an Aggregation Pipeline Builder tool to assist users in prototyping and debugging aggregation pipelines and exporting them to different programming languages. You can see the aggregation tool in MongoDB Compass in Figure 1.4:
Figure 1.4: MongoDB Compass
Studio 3T provides an Aggregation Editor tool to help you prototype and debug aggregation pipelines and translate them to different programming languages. You can see the aggregation tool in Studio 3T in Figure 1.5:
Figure 1.5: Studio 3T