Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"system." In a Collection Name in MongoDB

Tags:

mongodb

I just discovered a bizarre behavior exhibited by MongoDB.

Apparently, any collection name with the string "system." anywhere in it will just not function correctly.

To make matters worse, it won't even tell you anything is wrong!

It's really more a matter of curiosity, but does anybody have any idea why this would happen? Is it documented somewhere?

My assumption is that it uses ""system.*" collections to store things internally (like indexes) and doesn't want you messing with them, but this doesn't seem like the correct behavior to me.

like image 957
Kevin Dolan Avatar asked Jan 12 '11 04:01

Kevin Dolan


1 Answers

You are correct "system.*" is a reserved collection namespace used by MongoDB in each DB.

It is used to store indexes and users, etc.

SQL Server has many such tables too, and I don't believe they warn you not to use them either :)

But you could always put in a request for such functionality: http://jira.mongodb.org/

You can see them by running ...

> show collections

and you'll see something like ...

system.indexes

system.users

So, you can see your indexes for example:

> db.system.indexes.find()

From the MongoDB docs:

The .system.* namespaces in MongoDB are special and contain database system information. System collections include:

  • system.namespaces lists all namespaces.
  • system.indexes lists all indexes.
  • Additional namespace / index metadata exists in the database.ns files, and is opaque.
  • system.profile stores database profiling information.
  • system.users lists users who may access the database.
  • local.sources stores replica slave configuration data and state.
  • Information on the structure of a stored object is stored within the object itself. See BSON .

There are several restrictions on manipulation of objects in the system collections. Inserting in system.indexes adds an index, but otherwise that table is immutable (the special drop index command updates it for you). system.users is modifiable. system.profile is droppable.

http://docs.mongodb.org/manual/reference/system-collections/

like image 61
Justin Jenkins Avatar answered Oct 04 '22 08:10

Justin Jenkins