MongoDB

MongoDB: The Developer Data Platform | MongoDB

What is NOSQL?

The full form of NoSQL is Not Only SQL. In the NOSQL data is stored in a non-relational fashion. Means data is not stored in the tabular form. The name NoSql is given because there is no need to write queries like SQL. The query is inserting, deleting, updating and fetching.

Here is some example of NOSQL databases:

  1. MongoDB

  2. CouchBase

  3. ReThinkDb

  4. Redis

What is MongoDB?

MongoDB is a NoSQL database. In the MongoDB data is stored in the form of a document. MongoDB is a document-based database which internally stores data in the form of BSON, but we as developers can send or receive the data in the form of JSON. MongoDB automatically manages the conversion of BSON-JSON and JSON-BSON.

In simple terms, collections are a group of JSON documents.

One record is stored in the form of a document.

Here is some query which is used for fetching, updating, inserting, and deleting data from MongoDB.

List all databases in MongoDB

Command -> show databases;

Or

Command-> show dbs;

Result -> showing all the databases which are present in the MongoDB.

If we want to work on particular databases then we use this command:

Select a particular database to work on:

Command -> use name_of_database;

If we want to print all the documents of a collection:

Print all the documents:

Command-> db.collectionname.find();

If we want to create a new database:

command-> use new_database_name;

If we want to add a new collection:

command-> db.createCollection(“name_of_the_collection”);

How to add a new record to a collection?

To add a new record we can do:

Command -> db.collectionName.insertOne({key1:value1, key2:value2…})

How to add multiple records together?

To add multiple records at once in MongoDB we can use:

command-> db.collectionName.insertMany([

{

key1:value1,

key2:value2

},

{

key1:value1,

key2:value2

},

]);