MongoDB Tutorials

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 CollectionQuery DocumentsQuery on Embedded/Nested DocumentsQuery an ArrayQuery an Array of Embedded DocumentsSample CollectionI am going to use the below `books` collection for all the sample query. db.books.insertMany([ { "name" : "The Little Prince", "author" : { "name" : "Antoine de Saint-Exupery", "born" : 1900, "died" : 1944, "occupation" : ["Aviator", "writer"] […]... Read More »

MongoDB Data Types(BSON)

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.ArrayBinaryBooleanCodeDateDoubleIntegerMaxKey/MinKeyNullObjectObjectIdRegular ExpressionStringSymbolTimestampArrayArray is a data structure and It is used to store the group of elements. We […]... Read More »

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 collection. It will return `false` when collection to drop does not exist.Create Collection:First, We will create a topics3 collection in […]... Read More »

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] > db.books.insertOne({ 'title':'MongoDB', 'description':'Learn MongoDB with NoSQL', 'version':'4.x' }) { "acknowledged" : true, "insertedId" : ObjectId("5b8e859670e393ef22ee63ed") } > […]... Read More »

MongoDB Create Collection

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 > DOCUMENTSWe can create collections in two ways.Method 1:Using `createCollection()` method, We can create a collection in mongo database.Syntax:db.createCollection(name, options)In this shell command.`name` is […]... Read More »

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 isSyntax:db.dropDatabase()This command will drop the currently selected database. If we have not selected any database, It will drop the default database(test).Database List:If you want to get the […]... Read More »

MongoDB Create Database

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 exist2) will switch to the database If the database existsThe basic syntax for creating a new Mongo database isSyntax:use DATABASE_NAMEIf you want to create a new database […]... Read More »