DawnZHANG
DawnZHANG

Reputation: 387

How to drop a collection whose name contains "_"?

I create a collection in Mongodb with a name like "col", and it seems like with name contains character "", you cannot use db.COLLECTION_NAME.drop() to drop it??

enter image description here

the "_jihui" collection is what I'm referring to.

Upvotes: 0

Views: 108

Answers (2)

Oleks
Oleks

Reputation: 1633

Use getCollection() method for that purpose:

db.getCollection('_col').drop()

Upvotes: 1

satish chennupati
satish chennupati

Reputation: 2650

you can enclose your collection name in square brackets when the collection contain some kind of special characters in its name.

eg : db["my-db--collection"].drop()

Upvotes: 0

Related Questions