I love MongoDB, and a certain little ambiguity occurred to me and I was wondering if anyone had seen this before and possibly would know the answer :-).
in mongo, to reach into sub-objects, you use dot notation, for example:
db.persons.find({ "address.state" : "CA" })
which is simple enough. How (if it does at all) does mongo deal with the difference between:
{
"address" { "state" : "CA" }
}
and
{
"address.state" : "CA"
}
since dots are legal in keys as far as i know. Additionally, I believe that this would be a legal doc as well:
{
"address" { "state" : "A" },
"address.state" : "B"
}
in which case, I can see this query returning either "A"
or "B"
:
db.persons.find({}, {"address.state"}) // all docs selecting address.state as result.
Similar potential issue can arise I imagine with arrays as well:
{"a":["test"]}
which could be access with:
{"a.0"}
and of course
{"a" {"0" : "test"} }
which would also be access with:
{"a.0"}
thoughts? experiences? Is the conventional wisdom simply not to do that?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…