Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numeric Collection Name Remove

How can you drop a numeric collection from MongoDB?

PRIMARY> db.123456789011.remove({});
Tue Mar 20 08:42:51 SyntaxError: missing ; before statement (shell):1

PRIMARY> db.123456789011.drop({});
Tue Mar 20 08:43:13 SyntaxError: missing ; before statement (shell):1

Was created through a PHP script.. now I can't figure out how to remove this..

Thoughts?

Thank you

like image 301
Petrogad Avatar asked Mar 20 '12 15:03

Petrogad


People also ask

How do I change the name of a collection?

renameCollection() method is used to rename a collection. The new name of the collection. Enclose the string in quotes. If true, mongod drops the target of renameCollection prior to renaming the collection.

Can we rename collection name in MongoDB?

In MongoDB, you can use the renameCollection() method to rename or change the name of an existing collection. The new name of the collection. Optional, if true then mongod drops the target of renameCollection former to renaming the collection. The default value is false.

How do I delete collections?

Delete a collectionAt the bottom, tap Collections. Tap a collection. ​Delete collection. Check the box, then tap Delete.


1 Answers

I was having the same issue with a collection generated by a java class

db["1234"].drop()
Wed Jul  9 14:57:39.358 TypeError: Cannot call method 'drop' of undefined

and at the end used the following command to remove it.

db.getCollection('1234').drop()
like image 73
David Avatar answered Sep 18 '22 15:09

David