SyntaxError: Happy New Year

4 Likes

It’s the Javascript parser thingy.

The db.2022 has a special meaning in Javascript, hence it is not interpreted into db["2022"] meanwhile db.abc parsed as db["abc"]. It will be interpreted as an attribute only when the name starts with alphabet.

Similar thing happened for example with field names that has hyphen ("-") in it.
db.my-first-property doesn’t work. db["my-first-property"] works.
This is because the parser will treat it as db["my"] - first - property (arithmetic formula, value a minus value b minus value c).

If you have control over the naming, it’s better to give a database names and collection names contain only alphanumeric and always start with an alphabet (which is quite common across languages that you should not use identifier names starting with numerical digits), use underscore instead of hyphens for those names.

1 Like

@Daniel_Baktiar1 so, this was a bit of joke. Haha!

But, I really appreciate your response since someone might find it helpful (had they happened to have this issue) one day!

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.