Search code examples
mongodbmongo-shell

Switch / use <dbname> in MongoDB shell


I'm newbie with mongodb.

When I created the cluster it automatically created a database named < dbname > as far as I understood.

My problem now is, in the shell. How do I switch to this database and use it? If I try to switch to other existing dbs (use local / use admin) so it's okay. I tried to use < dbname > but I get an error saying < dbname > is not a valid database name.

Image provided - me trying to use < dbname > and getting an error

Thank you !


Solution

  • You create Database From Compass GUI and use invalid characters: enter image description here

    "The problem"

    From mongodb docs:

    https://docs.mongodb.com/manual/reference/limits/#Restrictions-on-Database-Names-for-Windows

    Restrictions on Database Names for Windows

    For MongoDB deployments running on Windows, database names cannot contain any of the following characters:

    /\. "$*<>:|?
    
    

    Example: enter image description here

    Solution

    Delete this database (By compass) - and create new database without < >.

    Out of topic: Better practice to use more semantic DB names like Trips, Orders, and so on (And not db-name).