MongoDB Introduction to nested queries in each document don't know where to hide, anyway I didn't find, a chance to find a post on the web, finally know the use of nested queries. So one of the problems in our application has been solved. Don't talk nonsense, now say the use of nested queries.
Suppose there is a collections in the MongoDB, and the data is as follows:
> Db.xx.find ()
{"_id": 1, "name": {"a": 2, "Last": 3}}
{"_id": 3, "name": {"1": 1, "2": 2, "3": 3}}
{"_id": 2, "name": {"1": 1, "2": 2}}
Now we're going to query the value of the _id=1 name in the record, and do the following:
> Db.xx.find ({"_id": 1},{"Name.first": 1, "_id": 0})
{' name ': {' 2}} '
OK, we know from the above example that the key to nested queries is "Name.first". Modifications to nested properties are similar, for example, if we want to name.first the query to the value of +2 in this record, then:
> db.xx.update ({"_id": 1},{$inc: {"Name.first": 2}})
> Db.xx.find ({"_id": 1},{"Name.first": 1, "_id": 0})
{' name ': {' 4}} '
OK, the value has changed.