Sowmay Jain
Sowmay Jain

Reputation: 955

Mongodb: How to drop a collection named "stats"?

I created a collection named "stats" but whenever I try to delete it by using db.stats.drop() cmd line. It shows an error.

TypeError: db.stats.drop is not a function

Even tried this.

db["stats"].drop

Any solution?

Upvotes: 1

Views: 260

Answers (1)

p.streef
p.streef

Reputation: 3815

if the collection exists db.stats.drop() should work (depending on the mongodb version maybe) or else perhaps db.getCollection("stats").drop();

but if all else fails, run: db.runCommand({drop : "stats"}) this should drop it if it exists without any error at least.

Upvotes: 2

Related Questions