Any working around with Mongodb key can't contain “.” or “$”?

后端 未结 1 576
南旧
南旧 2021-01-18 11:35

This kind of document are not accepted by Mongodb:

{\'.\':1}

if encode and decode by hand that\'s a pain. Any thoughts?

相关标签:
1条回答
  • 2021-01-18 11:38

    The Naming Restrictions on database, collection, and field names have practical purposes. They try to ensure queries are unambiguous and that valid filenames can be created.

    For example:

    • MongoDB uses dot notation to access elements of an array or subdocument.

    • MongoDB uses the dollar sign ($) to represent operators (eg. $inc).

    • Database names correspond to files created in the operating system, and there are reserved characters for path separators and wildcards.

    The obvious workaround (which is also suggested in the MongoDB manual) is to use a different character. For example, the Unicode full width equivalents of $ and . will display similarly but are not reserved:

    • U+FF04 (i.e. “$”)
    • U+FF0E (i.e. “.”)
    0 讨论(0)
提交回复
热议问题