Tag Archives: MongoDB

MongoDB Delete Collection

In this post, We will learn How to delete a collection from MongoDB. MongoDB shell command `db.collection.drop()` is used to drop the specified collection from the selected DB. Also, It will remove all the documents and indexes associated with the dropped collection. Syntax: db.collection_name.drop() Drop Query Response: It will return `true` when successfully drops a […]

MongoDB Drop Database

In this post, We will learn How to delete the existing mongo database. MongoDB shell command `db.dropDatabase()` is used to drop an existing database and their associated data files. It will block other operations While dropping a database. The basic syntax for deleting a database is Syntax: db.dropDatabase() This command will drop the currently selected […]

MongoDB Insert Document

This post will help us to learn How to add document in the MongoDB collection. MongoDB has `insert()` and `save()` method to add a document into collection. Syntax: db.COLLECTION_NAME.insert(document) Insert Single record: Example: > use learnmongodb switched to db learnmongodb > db.books.insert({ ‘title’:’MongoDB’, ‘description’:’Learn MongoDB with NoSQL’, ‘version’:’4.x’ }) WriteResult({ “nInserted” : 1 }) [OR] […]

MongoDB Query Document

This tutorial will help you to get a clear understanding to use the query operations using the db.collection.find() function. Sample Collection Query Documents Query on Embedded/Nested Documents Query an Array Query an Array of Embedded Documents Sample Collection I am going to use the below `books` collection for all the sample query. db.books.insertMany([ { “name” […]