How to use dot in field name?

后端 未结 7 1190
一整个雨季
一整个雨季 2020-11-30 07:19

How to use dot in field name ?

I see error in example:

db.test2.insert({ \"a.a\" : \"b\" })

can\'t have . in field names [a.a]
7条回答
  •  孤城傲影
    2020-11-30 07:56

    Actualy you may use dots in queries. See: http://www.mongodb.org/display/DOCS/Dot+Notation+%28Reaching+into+Objects%29

    Because of this special dot symbol mean you cannot use it in field names. Like you cannot use dot symbol in identifiers in most of programming languages.

    You may write query db.test2.find({ "a.a" : "b" }) but if you want to be able to write such a query you need to insert your object like so: db.test2.insert({"a": {"a": "b"}}). This will create document with the field named "a" with the value of embeded document containing the field named "a" (again) with the value "b".

提交回复
热议问题