I have a collection I created using mongoimport tool from a file. The problem is I had a typo in my command. Now I ended up with a collection that has two dashes in them. mycollection--file (do not forget the space before the dashes) Now mongodb wont let me drop the collection. db.mycollection--file.drop() It will get SyntaxError: Unexpected Identifier. It is not just drop but find or anyway to interact with the collection will get that syntax error. But it does get listed in the db, if you do show collections.
I believe this will work for you:
db["mycollection--file"].drop()
The square brackets with quotation marks syntax is useful for collection names that have characters in their names that interfere will normal shell commands.
UPDATE:
I've added, queried and then deleted from this collection name in my own mongodb database:
var x = {first:1}
db["mycollection--file"].save(x)
WriteResult({
"nMatched" : 0,
"nUpserted" : 1,
"nModified" : 0,
"_id" : ObjectId("53d96289aa812bcf293121df")
})
db["mycollection--file"].find()
{ "_id" : ObjectId("53d96289aa812bcf293121df"), "first" : 1 }
db["mycollection--file"].drop()
true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With