Skip to content

Example scripts for creating collections and running aggregation pipelines in MongoDB using the Node.js Driver. Includes support for capped, validated, and time series collections — ideal for learning, prototyping, or extending into CLI tools.

License

Notifications You must be signed in to change notification settings

Karl-Horning/mongodb-aggregation-pipelines

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🍃 MongoDB Aggregation Pipelines


📋 Table of Contents


🤓 Overview

This project includes example scripts for working with MongoDB collections using the MongoDB Node.js Driver. It covers both collection creation (including advanced options like capped and time series collections) and aggregation pipelines written in JavaScript.


📁 Project structure

/
├── aggregations/        # Scripts using aggregation pipelines with Node.js
│   └── *.js
├── create/              # Scripts to create collections using db.createCollection()
│   └── *.js

📦 Installation

Install the MongoDB Node.js Driver if not already installed:

npm install mongodb

🚀 Usage

📌 Seeding collections

  1. Open a script in the create/ folder.
  2. Update the database and collection names as needed.
  3. Run the script in a MongoDB shell or through a Node.js environment that supports direct MongoDB shell commands.

📖 Refer to the MongoDB createCollection() docs for further customisation.


🔍 Running aggregations

  1. Open a script in the aggregations/ folder.
  2. Ensure your MongoDB connection string is set correctly.
  3. Edit the agg variable to define your aggregation pipeline.
  4. Run the script using Node.js:
node aggregations/example.js

📚 Dependencies


📌 To Do

  • Add .env support for connection strings
  • Include example output or test data
  • Add pipelines for $facet, $graphLookup, and $lookup examples
  • Add performance profiling notes

🙋 FAQ

Q: Can I use this with Atlas or a remote MongoDB instance? A: Yes. Update the connection string to use your remote URI.

Q: Are the scripts safe to run in production? A: They're educational examples and should be reviewed before any production use.


📄 Licence

MIT © Karl Horning


👤 Author

Made with ❤️ by Karl Horning

About

Example scripts for creating collections and running aggregation pipelines in MongoDB using the Node.js Driver. Includes support for capped, validated, and time series collections — ideal for learning, prototyping, or extending into CLI tools.

Topics

Resources

License

Stars

Watchers

Forks