DEV Community

Cover image for MongoDB and Mongoose at a high level
Pavan Gudiwada
Pavan Gudiwada

Posted on

MongoDB and Mongoose at a high level

This blog gives you a high level understanding of what MongoDB and Mongoose are and some basic terminologies you might encounter while working with them.

MongoDB

MongoDB is a NoSQL database that lets you store data as “documents”. It is one of the four types of NoSQL databases. Here’s what the hierarchy of MongoDB looks like:

Term What is it?
Cluster Highest layer in MongoDB.
Database Group of collections. Used to group data and setting permissions.
Collection A group of related documents which need not follow the same structure. Some can have extra fields and some without them.
Document Individual data stored as binary JSON object. This is your actual data.

Mongoose

Mongoose is an NPM library that makes it easy for you to connect to any MongoDB cluster and perform CRUD (Create, Read, Update, Delete) operations.

Here’s what you need to know to work with Mongoose

Term What is it?
Cluster Connection The Mongoose Connection (e.g., mongoose.connect()) creates a way for you to communicate with your cluster
Schema It defines the structure, types, validation, and defaults for the documents. Created using new mongoose.Schema().
Model A class/constructor compiled from the Schema (mongoose.model()). You will use the model to get data from the Collection.
Data (Document) This is the object you create and manipulate in your application. It’s an instance of Model, meaning it’s like the template your data should fit into. It’s crated using const newUser = new User(data).
Save Turns the data into a binary JSON object and sends it to your cluster to be written to the Collection in the Database. You’ll use the .save()command to save your document.

While this is not extensive, it can serve as a refresher or reference when necessary.

Thanks for reading!

Top comments (1)

Collapse
 
pradumnasaraf profile image
Pradumna Saraf

Great blog, Pavan!