How to remove a MySQL collection named 'group'?


The group is a type of method in MongoDB. It shouldn’t be created as a collection name. Even if you created it, you can easily remove it using getCollection('group').drop();). Let us first create a collection with documents −

> db.createCollection('group');
{ "ok" : 1 }
> db.getCollection('group').insertOne({"StudentName":"Chris"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cb80fe9623186894665ae3c")
}
> db.getCollection('group').insertOne({"StudentName":"Robert"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cb80fef623186894665ae3d")
}

Following is the query to display all documents from the collection with the help of find() method −

> db.getCollection('group').find().pretty();

This will produce the following output −

{ "_id" : ObjectId("5cb80fe9623186894665ae3c"), "StudentName" : "Chris" }
{ "_id" : ObjectId("5cb80fef623186894665ae3d"), "StudentName" : "Robert" }

Following is the query to remove the collection named ‘group’ −

> db.getCollection('group').drop();

This will produce the following output −

True

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 30-Jul-2019

46 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements