Why you shouldn't use a Dash in a MongoDB Collection Name

Imagine you have a production instance of a MongoDB collection named construction-places and you want to investiage some data manually. Let's dive into the Docker container running the database and run a query on the collection with dash:

$ docker exec -it mongodb-planets mongo planets
MongoDB shell version: 2.6.12
connecting to: planets
>
> db.construction-places.find()
2016-07-26T07:41:22.137+0000 ReferenceError: places is not defined

Seems the name was a bad choice when it comes to the MongoDB command line.

Despite being able to query the collections...

> db['construction-places'].count()
42

it is a bad name for a MongoDB collection.

Show Comments