- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to drop a numeric collection from MongoDB?
In order to remove the numeric collection name, use the following syntax
db.getCollection("yourNumericCollectionName").drop();
First, create a numeric collection. Following is the query
> db.createCollection("2536464"); { "ok" : 1 }
Now insert some documents in the above collection. Following is the query
> db.getCollection("2536464").insertOne({"Record":1}); { "acknowledged" : true, "insertedId" : ObjectId("5ca254a46304881c5ce84b8e") } > db.getCollection("2536464").insertOne({"Record":2}); { "acknowledged" : true, "insertedId" : ObjectId("5ca254a76304881c5ce84b8f") } > db.getCollection("2536464").insertOne({"Record":3}); { "acknowledged" : true, "insertedId" : ObjectId("5ca254a96304881c5ce84b90") }
Following is the query to display all documents from a collection with the help of find() method
> db.getCollection("2536464").find().pretty();
This will produce the following output
{ "_id" : ObjectId("5ca254a46304881c5ce84b8e"), "Record" : 1 } { "_id" : ObjectId("5ca254a76304881c5ce84b8f"), "Record" : 2 } { "_id" : ObjectId("5ca254a96304881c5ce84b90"), "Record" : 3 }
Following is the query to remove numeric collection name
> db.getCollection("2536464").drop();
This will produce the following output
True
Now the numeric collection name has been removed successfully.
Advertisements