Mongo客户端无法访问带有下划线前缀的集合 [英] Mongo client can't access collections prefixed with an underscore

查看:172
本文介绍了Mongo客户端无法访问带有下划线前缀的集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Mongo中用下划线命名了一个集合,但是无法从外壳程序中访问它:

I named a collection with an underscore in Mongo, and can't access it from the shell:

meteor:PRIMARY> show collections
_assignments
chatmessages
(... other stuff)

尝试在第一个集合上运行任何功能都会导致错误:

Trying to run any function on the first collection results in an error:

meteor:PRIMARY> db._assignments.find()
Thu Jun 19 10:53:28.450 TypeError: Cannot call method 'find' of undefined

但是,其他集合可以正常工作:

However, other collections work fine:

meteor:PRIMARY> db.chatmessages.find()
{ "room" : "j5oau9DJ6GNpT9nR8", "userId" : "at9Kt8NNL4aeof6LE", "text" : "@nomad943 can you take a look at event #1?", "timestamp" : 1391806611977, "_id" : "26GbXa6c4B65FYRxC" }
{ "room" : "T7JfjBhri48bNHAfQ", "userId" : "B82LxmPBZWDnN4N2p", "text" : "Thinking #60 should be deleted, it's a duplicate of #36 and the region is wrong for the province", "timestamp" : ISODate("2014-06-18T18:57:56.480Z"), "_id" : "29pKqPhi4hgxCb2Ky" }

这是怎么回事?

推荐答案

除了外壳无法使用默认的辅助语法来解决这个问题外,我看不到其他问题.您仍然可以在外壳中访问这样命名的集合:

I don't see the problem other than the shell cannot address this with it's default helper syntax. You can still access collections named like this in the shell:

db.createCollection("_assignments")
{ "ok" : 1 }
db.getCollection("_assignments").find()
db.getCollection("_assignments").insert({ "a": 1 })
WriteResult({ "nInserted" : 1 })
db.getCollection("_assignments").find({ "a": 1 })
{ "_id" : ObjectId("53a36a4047234c4e9bb4feac"), "a" : 1 }

这篇关于Mongo客户端无法访问带有下划线前缀的集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆