mongodb 无法从 shell 访问集合 - SyntaxError: missing ; before 语句(外壳):1
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7111830/
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't access collection from the shell - SyntaxError: missing ; before statement (shell):1
提问by DavidA
I wrote a script that uses mongoimport to load csv files into mongodb. When I run this for two similar csv files (of the same type) both upload fine, however I can only access one of them from the mongodb shell. Here is a transcript of a mongodb shell session:
我写了一个脚本,使用 mongoimport 将 csv 文件加载到 mongodb 中。当我为两个类似的 csv 文件(相同类型)运行此文件时,它们都可以正常上传,但是我只能从 mongodb shell 访问其中一个。这是 mongodb shell 会话的记录:
> show collections
3mLgQAYJCq6_20110802
eTByWMY7zO6_20110802NonUniCode
system.indexes
> db.3mLgQAYJCq6_20110802
Thu Aug 18 18:44:49 SyntaxError: missing ; before statement (shell):1
> db.eTByWMY7zO6_20110802NonUniCode
vh.eTByWMY7zO6_20110802NonUniCode
However, I can access both collections from a python script and using mongoexport. I suspect there is a problem with the 3mLgQAYJCq6_20110802 file but I don't know where to start looking. Any ideas?
但是,我可以从 python 脚本和使用 mongoexport 访问这两个集合。我怀疑 3mLgQAYJCq6_20110802 文件有问题,但我不知道从哪里开始寻找。有任何想法吗?
回答by code_monk
This works for me when my collection names include special characters:
当我的集合名称包含特殊字符时,这对我有用:
db["3mLgQAYJCq6_20110802"].findOne();
回答by azhar_salati
The collection name should start with a letter or the underscore.You can get the info about the naming convention for the collections in mongodb from below link- http://www.mongodb.org/display/DOCS/Collections
集合名称应以字母或下划线开头。您可以从以下链接获取有关 mongodb 中集合的命名约定的信息 - http://www.mongodb.org/display/DOCS/Collections
回答by Karoly Horvath
lovely collection names... it's probably because it's starts with a 3
.
可爱的集合名称...可能是因为它以3
.