MongoDB: Some Basics & CRUD

Edward
3 min readJan 4, 2021

MongoDB is a Document Oriented Database… Ok, what’s that?

MongoDB is a NoSQL (does not follow a structure) database that stores data in a way that is not just relational tables.

According to the MongoDB website “As a developer, you think in objects. Now your database does too.”

That simple statement best summarizes the perk of using MongoDB instead of using an SQL database. To help understand what storage in SQL is like, think of an excel data sheet with fixed header cells. For example, “cars” would be the title on the header line and if you wanted to add different models of cars to your list, you would have to select a cell underneath that title cell and type in “Shelby Cobra”. The next header cell might have a “Make/Year” title where you would put the year and so on. This style of storing data is fine for many situations but it has to follow a structure. If you had this car database list for years and wanted to add a new title like “Has XM Radio”, you would need to add this title for the entire data base. So now, think back to MongoDB’s statement on thinking like objects. Wouldn’t it be nice to add information as an object with key value pairs that can be created per instance instead of making a blanket list that every insertion would have to follow? This is precisely what MongoDB does along with many other great features.

In this example above, we can enter data per instance that not only contains key/value pairs per instance but the values can also be key/value pairs as well. MongoDB automatically creates the keys the same way we were creating titles in the excel example and saves the value to that title (key). And with the CRUD process that MongoDB allows, you can also easily find and manipulate the data at anytime.

So what is CRUD besides an unpleasant side affect of bad allergies?

Two ways to use the CRUD procedure are with the mongo shell or with Express. To help give a general understanding of the concept I will just explain “what” the techniques do instead of giving examples of “how” to use them.

CRUD stands for:

  • Create Operations
  • Read Operations
  • Update Operations
  • Delete Operations

Create Operations more or less creates a folder for you to save the information into the database. This is done with a simple keyword command followed by a simple method to add the data.

Read Operations is how you search through the database and find the information you desire. This is with the use of a simple method.

Update Operations is the most difficult of the CRUD process as it first requires finding the information you would like to manipulate. Once located you must perform particular code specific to mongoDB to make the change.

Delete Operations is self explanatory and only requires a simple method to either delete an entire portion of the data or a certain instance.

Conclusion: Few More Benefits of MongoDB

According to the 2020 developers survey that Stack Overflow releases every year, MongoDB was picked as the most wanted (in demand) database. So probably worth your time to check it out. Some main users of MongoDB are Ebay, Adobe, Google, EA Sports, SEGA, Verizon, and Intuit(TurboTax). Also, MongoDB works great with JavaScript and recognized the language in its shell. And not only does this database allow you to store as objects, it also compresses the data down using BSON which is a more compressed way to save data than JSON as it stores the information as binary code instead of text-based like JSON. I hope this has given you a better understanding of what MongoDB does and is capable of.

--

--