Search code examples
javascriptmongodbmongodb-querymongodb-shell

MongoDB: How to query a collection named "version"


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?


Solution

  • 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.