Skip to content

Commit dbd49a5

Browse files
authored
Merge pull request #2926 from bagerard/update_doc_querying_dict_depend_order
Improve doc for querying by dict
2 parents f024fc9 + 42f1fc5 commit dbd49a5

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

docs/guide/querying.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ syntax::
3939
# been written by a user whose 'country' field is set to 'uk'
4040
uk_pages = Page.objects(author__country='uk')
4141

42+
.. warning::
43+
44+
Be aware that MongoDB considers field order when matching an embedded
45+
document. As a result, querying a :class:`~mongoengine.fields.DictField` or
46+
:class:`~mongoengine.fields.MapField` against a complete dictionary only
47+
matches when its keys are in the same order as the stored document. The same
48+
applies when querying an :class:`~mongoengine.fields.EmbeddedDocumentField`
49+
with an embedded document instance. For example, this query may not match
50+
when the stored keys are in the opposite order::
51+
52+
SurveyResponse.objects(
53+
answers={"question_2": "no", "question_1": "yes"},
54+
)
55+
56+
Query individual dictionary keys to match their values regardless of
57+
order::
58+
59+
SurveyResponse.objects(
60+
answers__question_1="yes",
61+
answers__question_2="no",
62+
)
63+
4264
.. note::
4365

4466
(version **0.9.1+**) if your field name is like mongodb operator name (for example

0 commit comments

Comments
 (0)