MongoDB 字段名称中不允许使用哪些字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9759972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 12:32:57  来源:igfitidea点击:

What characters are NOT allowed in MongoDB field names?

mongodb

提问by Blacksad

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

我当然想通了。和 SPACE 是不允许的。还有其他禁止字符吗?

回答by Acorn

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

您可以在字段名称中使用任何不特殊的 (UTF8) 字符(包含“.”,或以“$”开头)。

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

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

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

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

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

不过,通常最好坚持使用带下划线的小写字母数字。

回答by Dave

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.

需要注意的另一件事是,您可以创建一个名为“query”的属性名称,然后在其上使用查询运算符,这使得执行大量查询变得很尴尬。

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:

不等于 ($ne) 不:

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