任何使用Mongodb键的方法都不能包含“.".或"$"? [英] Any working around with Mongodb key can't contain "." or "$"?

查看:583
本文介绍了任何使用Mongodb键的方法都不能包含“.".或"$"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Mongodb不接受此类文档:

This kind of document are not accepted by Mongodb:

{'.':1}

如果用手编码和解码,那是很痛苦的.有什么想法吗?

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

推荐答案

对数据库,集合和字段名称的命名限制具有实际用途.他们试图确保查询是明确的,并且可以创建有效的文件名.

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.

例如:

  • MongoDB使用点符号来访问以下元素数组或子文档.

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

MongoDB使用美元符号($)表示运算符(例如$inc).

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.

一种明显的解决方法(在MongoDB中也建议手册)是使用其他字符.例如,$.的Unicode全角等效项将显示类似,但不保留:

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(即"$")
  • U + FF0E(即.")

这篇关于任何使用Mongodb键的方法都不能包含“.".或"$"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆