Search code examples
node.jsmongodbmongoosees6-modules

Using the ° symbol in Mongo model name


I'm using MongoDB with mongoose and NodeJS. I have a model name where I want to include the ° symbol.

However, when I attempt to use it, I get an error in the terminal:

export default m°celsius;


SyntaxError: Invalid or unexpected token
at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:115:18)
at ESMLoader.moduleProvider (node:internal/modules/esm/loader:289:14)

But without this ° symbol in the name, there is no issue.

I was reading through the limitations and naming restrictions of MongoDB here: https://www.mongodb.com/docs/manual/reference/limits/ - but I see no mention about restriction on this symbol.

Also reading through the mongoose docs about Model here: https://mongoosejs.com/docs/api/model.html - but also see no mention of this.

I recently update my NodeJS, MongoDB and Mongoose. I did not have this issue before.


Solution

  • Plainly put, the degree symbol (°) is not valid in a variable name. Instead, consider naming your model mDegCelsius or something similar, which still portrays the same information in a reasonable (and valid) format.