Error using Mongo shell in mongo compass app

@Wiktor_Janiszewski The MongoDB shell is a JavaScript environment and will evaluate its input as JavaScript before running it. This means that

db.cross-app-test.findOne({})

is interpreted as

db.cross - app - test.findOne({})

with the - signs standing for literal subtraction operations.

You can work around this by using either of the following:

db['cross-app-test'].findOne({})
db.getCollection('cross-app-test').findOne({})

This is an inherent limitation when using hyphen characters in collection names.

3 Likes