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 Use show dbs command from mongo shell to list all the available databases on MongoDB server. This will show the database name with there size. Example: > show dbs 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 MongoDB does not provide commands to create a database. You can use use dbName statement to select a database in the mongo shell. Use the following example: Syntax: > use DATABASE_NAME Limitations MongoDB database names cannot be empty and must have fewer than 64 characters. Create Database First, of the all, Use below command to select database. To create a new database make sure it not exists. > use mydb You have a database name selected. Now you need to insert at least one document to keep…

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