Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

EXPERIMENT NO-2

AIM: Create and Delete Database and Collection


in MongoDB.

THEORY:

1) CREATE DATABASE:
MongoDB use DATABASE_NAME to
create database. The command will create
a new database if it doesn’t exist,
otherwise it will return the existing
database.

Syntax: use DATABASE_NAME

Example:

2) DROP DATABASE:
 Dropping a database means deleting
the database and also deleting all the
associated data files.
 The command used for deleting a
database is dropDatabase.

Syntax: db.dropDatabase()

Example:

3) CREATE COLLECTION:
 MongoDB.db.createCollection (name,
options) is used to create collection.
 In the command, name is name of
collection to be created. Options is a
document and is used to specify
configuration of collection.
Syntax: db.createCollection(name,
options)

Example:

4) DROP COLLECTION:

MongoDB’s db.collection.drop() is used to


drop a collection from the database.

Syntax: db.COLLECTION_NAME.drop()

Example:

CONCLUSION:

Hence, we learned how to create and


delete database and collection.

You might also like