What characters are NOT allowed in MongoDB field names?

前端 未结 2 390
不知归路
不知归路 2020-11-27 21:14

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

相关标签:
2条回答
  • 2020-11-27 21:25

    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' } });
    
    0 讨论(0)
  • 2020-11-27 21:34

    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.

    0 讨论(0)
提交回复
热议问题