Mongoose is an ODM that takes away the complexity of all the code you'd have to think and write and that you realise that could be abstracted and reused between all pieces of Entities your application will require.

Two main features will help you from the beginning

  • Handles the connection to the MongoDB instance using the official driver behind the scenes
  • Allows to describe your Entities, or Documents how I should name them better, using Schema implementation that offers you the Model, as expected in the MVC pattern.

The Schema is what you need to look into first, than Models.

The Models will allow you to do all CRUD operations, supports pre built in Validation that can be extended with any custom rules, comes with built in Getters and Setters and allows any custom ones.

Clever feature to keep in mind

Also, Mongoose allows you to hook plugins. This is what DRY really means. Any small problem that can be solved and it's solution reused in Models is a prime candidate to be a plugin. You might be even lucky to find already built Mongoose plugins in the community that are well maintained.

One notable plugin I've found useful is the mongoose-version that helps me implement versioning and moderation states. The quick usage would be like revisions of posts in WordPress.

Running MongoDB on your local working environment

My choice for services has been Docker for many years. Running MongoDB is just one easy thing to run it with Docker. I'm using Kitematic to control my Docker containers and for any project or any test, I'm just starting a new container, a MongoDB container in this case, rename it and on the the container settings, I'm hitting save on the Hostname / Ports page to keep the localhost port persistent between restarts.

Conclusion

Mongoose has more features than what I've mentioned as a starting point for a beginner, but those are even for me something to look more in the future. Just the above are decent enough to get me started in describing my main Entities for my second hand cars selling application.

Have fun using MongoDB with this library and feel free to share any other thoughts in comments.