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.
/
├── aggregations/ # Scripts using aggregation pipelines with Node.js
│ └── *.js
├── create/ # Scripts to create collections using db.createCollection()
│ └── *.js
Install the MongoDB Node.js Driver if not already installed:
npm install mongodb
- Open a script in the
create/
folder. - Update the
database
andcollection
names as needed. - 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.
- Open a script in the
aggregations/
folder. - Ensure your MongoDB connection string is set correctly.
- Edit the
agg
variable to define your aggregation pipeline. - Run the script using Node.js:
node aggregations/example.js
- Add
.env
support for connection strings - Include example output or test data
- Add pipelines for
$facet
,$graphLookup
, and$lookup
examples - Add performance profiling notes
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.
MIT © Karl Horning
Made with ❤️ by Karl Horning