 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- 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.
Advertisements
 