You're going to have to deal with databases as a developer. Now, I know what you are thinking …But I am just a front-end developer? Well, as an employer, I wouldn't want someone that's completely green when it comes to the backend, so you'll be doing yourself a lot of good by familiarizing yourself with what the backend entails, databases especially. This article explains MongoDB CRUD operations to you, the four primary database operations in any database. They enable you to Create, Read, Update and Delete data from your Database. The CRUD acronym stands for;
C- Create
R -Read
U – Update
D – Delete
Create
The C stands for Create. This is how you add new items to your Database. The items may be objects or individual items. If the collection doesn't exist, this operation will create a new one for you. Collection, in this case, refers to the name of your Database. Below is an example of how you insert items into a database called students. You can insert one or many at the same time.
- db.collection.insertOne()
- db.collection.insertMany()
Read(R)
This operation enables us to read the information available in our Database from the name itself. We use a method called to find to do this.
- db.collection.find()
find with no query inside returns the entire database.
- db.collection.find(query)
Inside the bracket, you feed the specific item you are looking for.
Update(U)
This operation helps one make changes to an already existing database. Inside the brackets, you will specify the value pairs you are interchanging or the ones you're adding inside.
db.collection.updateOne()
db.collection.updateMany()
Delete
Delete the object or items that you do not want in your collection. MongoDB provides the following methods for deleting. Similar to the insert command, you can delete one or delete many simultaneously.
db.collection.deleteOne()
db.collection.deleteMany()
I hope this makes your life easier. Feel free to add your comments below. And make suggestions on what you want me to write about next.