Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to remove a MySQL collection named 'group'?
The group is a reserved method name in MongoDB. While you can create a collection named "group", it requires special syntax to access. To remove such a collection, use getCollection('group').drop() method.
Syntax
db.getCollection('group').drop();
Create Sample Collection
Let us first create a collection named "group" with some sample documents ?
db.createCollection('group');
{ "ok" : 1 }
db.getCollection('group').insertMany([
{"StudentName": "Chris"},
{"StudentName": "Robert"}
]);
{
"acknowledged" : true,
"insertedIds" : [
ObjectId("5cb80fe9623186894665ae3c"),
ObjectId("5cb80fef623186894665ae3d")
]
}
Verify Collection Data
Display all documents from the collection using find() method ?
db.getCollection('group').find();
{ "_id" : ObjectId("5cb80fe9623186894665ae3c"), "StudentName" : "Chris" }
{ "_id" : ObjectId("5cb80fef623186894665ae3d"), "StudentName" : "Robert" }
Remove the Collection
Now remove the collection named "group" using the drop() method ?
db.getCollection('group').drop();
true
Key Points
- Use
getCollection()method to access collections with reserved names like "group". - The
drop()method permanently removes the entire collection and all its documents. - Returns
trueif the collection was successfully dropped.
Conclusion
Collections with reserved names like "group" require getCollection() method for access. Use db.getCollection('group').drop() to permanently remove such collections from your MongoDB database.
Advertisements
