无法从 mongodb 中删除集合
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13661801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can not delete collection from mongodb
提问by Salvador Dali
Can not delete the collection from the shell,
无法从shell中删除集合,
The thing that the collection is available and my php script is accessing it (selecting|updating)
集合可用并且我的 php 脚本正在访问它(选择|更新)
But when I used:
但是当我使用:
db._registration.drop()
it gives me an error:
它给了我一个错误:
Date, JS Error: TypeErrorL db._registration has no properties (shell): 1
回答by Salvador Dali
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 .
问题不在于删除集合。问题在于访问集合。因此,您将无法从 shell 更新、查找或使用它执行任何操作。正如在mongodb JIRA中指出的那样,当集合包含诸如_
,-
或 之类的字符时,这是一个错误。
Nevertheless this type of names for collections is acceptable, but it cause a problem in shell.
尽管如此,这种类型的集合名称是可以接受的,但它会导致 shell 出现问题。
You can delete it in shell with this command:
您可以使用以下命令在 shell 中删除它:
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).
但我宁愿重命名它(当然,如果可能的话并且不会有很多变化)。
回答by Michael Michelis
You can also use:
您还可以使用:
db["_registration"].drop()
which syntax works in JS as well.
哪种语法也适用于 JS。
回答by Manas
For some reason the double quotes "_registration" did not workfor me .. but single quote '_registration' worked
出于某种原因,双引号“_registration”对我不起作用..但单引号“_registration”有效