In this post, We will learn How to create a collection in MongoDB. MongoDB is stored in the format of documents and Documents are stored in the collection. Collections are stored in the database. Collections is a group of MongoDB documents like a table. MONGO DATABASE > COLLECTIONS > DOCUMENTS We can create collections in […]
Tag Archives: MongoDB
This post will help you to create and learn about a database in MongoDB. In the mongo shell, using `use DATABASE_NAME` command, We can create a MongoDB. `use ` command will do the below actions. 1) will create a new database If a database does not exist 2) will switch to the database If the […]
MongoDB stores the documents as BSON documents. BSON means, it is encoded binary format of JSON. BSON is providing the many data types to store the javascript objects into mongo collection. MongoDB supports the all type of BSON data types. You can get the list of BSON data types Which is supported by mongo db. […]
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 […]
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 […]
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] […]
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” […]