Wednesday 28 March 2018

How to create collection and drop collection in Mongodb 3.6?

To create collection in Mongodb 3.6 command is:-

The createCollection() Method

db.createCollection(Name, Options)

Name:- String Name of the collection to be created
Options:- Document(Optional) Specify options about memory size and indexing

Note:- 

In MongoDB, you don't need to create collection. MongoDB creates collection automatically, when you insert some document.

You can check the created collection by using the command show collections.

e.g.
use practice
show collections

The drop() Method

MongoDB's db.collection.drop() is used to drop a collection from the database.

Syntax

Basic syntax of drop() command is as follows −
db.collectionName.drop()

drop() method will return true, if the selected collection is dropped successfully, otherwise it will return false.

No comments:

Post a Comment