- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 can I drop a collection in MongoDB with two dashes in the name?
Let us first see the syntax to drop a collection −
db.getCollection("yourCollectionNameWithTwoDashes").drop();
For demo, we will create a collection name with two dashes as shown below −
> db.createCollection("company--EmployeeInformation"); { "ok" : 1 }
Create the above collection “company--EmployeeInformation “ with documents. Following is the query:
>db.getCollection("company--EmployeeInformation").insertOne({"CompanyName":"Amazon","EmployeeName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c5ff6d78f205348bc654") } >db.getCollection("company--EmployeeInformation").insertOne({"CompanyName":"Google","EmployeeName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c60b6d78f205348bc655") }
Following is the query to display all documents from a collection with the help of find() method −
> db.getCollection("company--EmployeeInformation").find();
This will produce the following output −
{ "_id" : ObjectId("5cd7c5ff6d78f205348bc654"), "CompanyName" : "Amazon", "EmployeeName" : "Chris" } { "_id" : ObjectId("5cd7c60b6d78f205348bc655"), "CompanyName" : "Google", "EmployeeName" : "Robert" }
Let us now drop a collection in MongoDB with two dashes in the name −
> db.getCollection("company--EmployeeInformation").drop();
This will produce the following output −
True
Look at the above output, we have dropped the collection name with two dashes.
- Related Articles
- How to drop a collection in MongoDB?
- How can I rename a collection in MongoDB?
- How to drop a numeric collection from MongoDB?
- How to drop a MongoDB Collection using Java?
- Can we use the “.” symbol in MongoDB collection name?
- How can I change the field name in MongoDB?
- Variable collection name in MongoDB shell with JavaScript?
- Change collection name in MongoDB?
- Renaming column name in a MongoDB collection?
- How can I aggregate collection and group by field count in MongoDB?
- How do I query a MongoDB collection?
- How do I display the indexes of a collection in MongoDB?
- How I can use a database-name with special characters like " customer_tracker-990" in MongoDB console
- How do I drop a MongoDB database from the command line?
- How can I search a collection to find a nested value in one of its documents in MongoDB?

Advertisements