2

I'm working with a mongo database that contains a collection named "version". Now it seems "db.version()" is by itself a reserved function and the collection name is hidden by it.

Using the Mongo Java Driver it's possible to retrieve data from the collection, how do I do it using the CLI?

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317

1 Answers1

4

You can do it like this:

db.getCollection("version").find()

The last form being essentially the same a you do in the Java driver or indeed in many language implementations where dynamic binding is not available.

The same applies for any other form where the name would not be allowed in the shell, such as:

db.getCollection("example@example.com").find()

Actually all that happens under the hood in the shell is that this official method is called.

Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
  • db["version"].find() doesn't work, same error message: "TypeError: Object function (){ return this.serverBuildInfo().version; } has no method 'find'", but db.getCollection() does. Thanks! –  Sep 04 '14 at 07:53
  • 1
    @dnno "version" seems to be the exception here. You can generally use the same syntax for other collection names though. – Neil Lunn Sep 04 '14 at 07:59