DEV Community

Cover image for MongoDB
sndp
sndp

Posted on

MongoDB

MongoDB

What is mongodb?

MongoDB is open-source, non-relational hence document-based database heavily used for modern day software applications. Developed by MongoDB Inc. in 2009 and released many versions and the current being 5.0.5 released on 6th December 2021.

Mongodb uses C++, Go, JavaScript, Python as its development languages. Mongodb can be used in many web applications with support of many languages mainly javascript since mongodb data models heavily use javascript to mutations of these documents and it is easy with js.

Mongodb database is famous for its high performance, availability, and scaling. Mongodb is cross-platform so developers can easily focus on developing for multiple platforms easily.

Mongodb structure

Mongodb has major types of databases we can select for our development area. They are,

Local development

For local development or for standalone applications developers can use this version of database of mongodb. We can use this version of mongodb to make to-do list and calender like apps and mobile apps for android and ios platforms.
We can use mongodb local development environment for our apps for unlimited usage and with our storage device capacity.

Cloud development

For cloud development or for distributed development of web apps or web-based mobile and desktop applications we can use a cloud database version of mongodb called Mongodb Atlas. So your development team can develop with their mongodb atlas authentication for involve in development of your web application.
We can use cloud development environment for transactions with 100 connections and capacity of 512mb of cloud data storage free.

When our application go viral and if we had to scale up then mongodb atlas can extend the capacity on par with requirements.

Inside mongodb

Any type of above two takes the same architecture of database but different in the context of data storage methods one involves with os for storing and another uses api calls for cloud.

  • Each mongodb database has collections. This is similar to tables of a mysql database.

  • Each collection has records which are documents.

  • Each document contains key-value pairs like in a json object but in which keys are also quoted.

  • These keys-value pairs are what defines the record.

eg:

{
   "_id": "5ewr3122rwer12323123",
   "name": "John Doe" , 
   "username": "JohnsDoe123", 
   "email": "johndoe123@abc.xyz"
}
Enter fullscreen mode Exit fullscreen mode

But each of these document contains how to uniquely identify a document (object) which is called the objectID or id which is like "_id": "5ewr3122rwer12323123" mentioned in example.

These values can take the form of strings, arrays, other objects, date objects etc.

We can version these documents according to which we can mutate after the new versions without mutating the original data models.

Hence each document can be different from earlier versions of documents and also modify to new models when using them with a orm like mongoose for nodejs development environment. Which is a way of making this dynamic structure of mongodb some schematic for our needs.

Can use methods for CRUD operations for both single record operations and multiple record and many querying methods for use in our applications.

eg:

find()
Enter fullscreen mode Exit fullscreen mode

Find documents of a collection.

save()
Enter fullscreen mode Exit fullscreen mode

Save document to a collection.

updateOne()
Enter fullscreen mode Exit fullscreen mode

Updates a document.

delete()
Enter fullscreen mode Exit fullscreen mode

Delete method deletes a document.

findByIdAndDelete()
Enter fullscreen mode Exit fullscreen mode

Finds a document for given ObjectID and deletes it.

findByIdAndUpdate()
Enter fullscreen mode Exit fullscreen mode

Finds a document for given ObjectID and updates it with given values.

deleteOne()
Enter fullscreen mode Exit fullscreen mode

Deletes the first document from the selected resultset/collection.

Opposed to relational databases the mongodb's querying takes easy approach.
And no foreign keys used for the data delete and updates so collisions handling with on-update and on-delete actions are not needed but can implement a solution by developer's side and it is possible.

What to offer

Mongodb offers mainly,

  1. Mongodb database instance
    The instance of mongodb database and driver running as a service.

  2. Mongodb shell
    A command line application for initialize and manage databases.

  3. Mongodb compass
    A graphical user interface to manage the databases.
    (eg: like mysql workbench for mysql)

And also including Mongodb Atlas database-as-a-service.

Frequently seen on

Mongodb can be seen in action on,

  1. E-Commerce systems
  2. Blogs (medium)
  3. Social networks (Codeacademy)
  4. Transportation (Uber, Lyft)
  5. API Development as Data Layer

Download MongoDB.

Learn more about mongodb using following link.

https://docs.mongodb.com/manual/tutorial/getting-started/

Latest comments (0)