Assume that there is such a document:
DB. XXX. Remove ();
DB. xxx. insert ({"ID": 1, "members": [{"name": "buleriver1", "Age": 27, "gender": "M "}, {"name": "buleriver2", "Age": 23, "gender": "F" },{ "name": "buleriver3", "Age": 21, "gender": "M"}]});
You cannot use dB. XXX. Find ({"members": {"name": "buleriver1"});. The query result is an empty set. The result can be obtained only when one matching is complete. Therefore:
DB. XXX. Find ({"members": {"name": "buleriver1", "Age": 27, "gender": "M "}});
The result is displayed.
If the key value is reversed, no result is returned:
DB. XXX. Find ({"members": {"Age": 27, "name": "buleriver1", "gender": "M "}});
The result is an empty set.
We can query this as follows:
DB. XXX. Find ({"members. Name": "buleriver1 "});
Yes.
If two attributes are required:
DB. XXX. Find ({"members. Name": "buleriver1", "members. Age": 27 });
You can also query the results.
Let's try again:
DB. XXX. Find ({"members. Name": "buleriver1", "members. Age": 23 });
You can also query the results.
However, we should note that buleriver1 is the key value of the first element in the array, while 23 is the key value of the second element in the array, so that we can query the result.
For some of our applications, this is obviously not the result we want. Therefore, we should use $ elemmatch:
DB. XXX. Find ({"members": {"$ elemmatch": {"name": "buleriver1", "Age": 27 }}});
You can query the results, while
DB. XXX. Find ({"members": {"$ elemmatch": {"name": "buleriver1", "Age": 23 }}});
No results are found. Therefore, this is exactly what we want.