user1015104
user1015104

Reputation:

Can not delete collection from mongodb

Can not delete the collection from the shell,

The thing that the collection is available and my php script is accessing it (selecting|updating)

But when I used:

db._registration.drop()

it gives me an error:

Date, JS Error: TypeErrorL db._registration has no properties (shell): 1

Upvotes: 22

Views: 38347

Answers (4)

Keith Woodward
Keith Woodward

Reputation: 1

None of these recommendations work for me under RHEL8.9. I usually can drop an collection with ease but not this time; it was created by mistake in a script I was running. There was a misspelling error.

Upvotes: 0

Salvador Dali
Salvador Dali

Reputation: 222969

The problem is not with deleting the collection. The problem is with accessing the collection. So you would not be able to update, find or do anything with it from the shell. As it was pointed in mongodb JIRA, this is a bug when a collection has characters like _, - or .

Nevertheless this type of names for collections is acceptable, but it cause a problem in shell.

You can delete it in shell with this command:

db.getCollection("_registration").drop()

or this

db['my-collection'].drop()

but I would rather rename it (of course if it is possible and will not end up with a lot of changing).

Upvotes: 53

Michael Michelis
Michael Michelis

Reputation: 141

You can also use:

db["_registration"].drop()

which syntax works in JS as well.

Upvotes: 0

Manas
Manas

Reputation: 399

For some reason the double quotes "_registration" did not workfor me .. but single quote '_registration' worked

Upvotes: -1

Related Questions