MongoDB – Insert Document

MongoDB Insert Document Use db.collection.insert() method to insert new document to MongoDB collection. You don’t need to create the collection first. Insert method will automatically create collection if not exists. Syntax > db.COLLECTION_NAME.insert(document) Insert Single Document Insert single ducument using the insert() method. It’s required a json format of document to pass as arguments. > db.users.insert({ “id”: 1001, “user_name”: “rahul”, “name”: [ {“first_name”: “Rahul”}, {“middle_name”: “”}, {“last_name”: “Kumar”} ], “email”: “[email protected]”, “designation”: “Founder and CEO”, “location”: “India” }) Output: WriteResult({ “nInserted” : 1 }) Insert Multiple Documents To insert multiple…

Read More

MongoDB – Show Collection

Mongodb Show Collection Use show collections command from MongoDB shell to list all collections created in the current database. First, select the database you want to view the collection. Mongodb Show Collection Select your database and run show collections command to list available collections in MongoDB database. > use mydb > show collections Output: TECADMIN accounts mycol pproducts users Get Collections Information To find detailed information about the database collections use .getCollectionInfos() function. This will provide an array of documents with collection information, such as name and options. > db.getCollectionInfos();…

Read More

MongoDB – Drop Database

MongoDB Delete Database The dropDatabase() command is used to delete the current database calculating all the associated data files. To remove any database first you need to select that database. You can use show dbs command to list available databases. > use mydb Now run the drop database command to delete the currently selected database. Before deleting any database, make sure to take backup Mongodb database. > db.dropDatabase() { “dropped” : “mydb”, “ok” : 1 }

Read More

MongoDB – Show Databases

MongoDB show databases In MongoDB, you can use the show dbs command to list all databases on a MongoDB server. This will show you the database name, as well as the size of the database in gigabytes. Example: > show dbs Output local 0.000GB mydb 0.001GB tecadmin 0.083GB You can select any database using the use statement and work on it.

Read More

MongoDB – Create Database

MongoDB Create Database Creating a new database with MongoDB is a straightforward process, but there are a few prerequisites that you need to consider before you can get started. In this article, I’ll walk you through the steps for creating a MongoDB database, as well as some common mistakes to avoid. By the end of this article, you’ll have the knowledge and confidence to create a new database with MongoDB quickly and easily. Syntax: > use DATABASE_NAME Limitations MongoDB database names cannot be empty and must have fewer than 64…

Read More

MongoDB Tutorial

This is our new series of tutorials for MongoDB NoSQL database. In this tutorial list you will find most of the basic tutorial about MongoDB which will help you to learn MongoDB and work with it.

Read More