Blacksad
Blacksad

Reputation: 15422

What characters are NOT allowed in MongoDB field names?

I figured out that of course . and SPACE aren't allowed. Are there other forbidden characters ?

Upvotes: 34

Views: 45849

Answers (2)

Dave
Dave

Reputation: 2576

Something else to look out for is the fact that you can make a property name called "query" but then use query operators on it, making it awkward to do a large number of queries.

Example:

Insert document with a property named

db.coll.insert({ query: 'foo' });

Equality query works:

db.coll.findOne({ query: 'foo' });    

Not equal ($ne) does not:

db.coll.findOne({ query: { $ne: 'bar' } });

Upvotes: 1

Acorn
Acorn

Reputation: 50497

You can use any (UTF8) character in the field name which aren't special (contains ".", or starts with "$").

https://jira.mongodb.org/browse/SERVER-3229

https://stackoverflow.com/a/7976235/311220

It's generally best to stick with lowercase alphanumeric with underscores though.

Upvotes: 51

Related Questions