Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo client can't access collections prefixed with an underscore

Tags:

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" } 

What's going on here?

like image 511
Andrew Mao Avatar asked Jun 19 '14 14:06

Andrew Mao


People also ask

How do I view collections in MongoDB?

To obtain a list of MongoDB collections, we need to use the Mongo shell command show collections . This command will return all collections created within a MongoDB database. To be able to use the command, we'll first need to select a database where at least one collection is stored.

Is MongoDB collection name case sensitive?

Database names and Collection names are case sensitive. You can always recreate the DB/Collection with the appropriate name. The Mongo Shell is a interactive JS interpreter. and because JS is case sensitive then the shell is.

What is MongoDB Index Key limit?

A collection cannot have more than 64 indexes. The length of the index name cannot be longer than 125 characters. A compound index can have maximum 31 fields indexed.

What are the limitations of MongoDB?

The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth. To store documents larger than the maximum size, MongoDB provides the GridFS API.


2 Answers

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 } 
like image 158
Neil Lunn Avatar answered Nov 07 '22 07:11

Neil Lunn


This is a known bug. Don't prefix collections with underscores.

https://jira.mongodb.org/browse/SERVER-445

like image 42
Brad M Avatar answered Nov 07 '22 06:11

Brad M