@@ -53,6 +53,16 @@ lists that contain that item will be matched::
53
53
# 'tags' list
54
54
Page.objects(tags='coding')
55
55
56
+ Raw queries
57
+ -----------
58
+ It is possible to provide a raw PyMongo query as a query parameter, which will
59
+ be integrated directly into the query. This is done using the ``__raw__ ``
60
+ keyword argument::
61
+
62
+ Page.objects(__raw__={'tags': 'coding'})
63
+
64
+ .. versionadded :: 0.4
65
+
56
66
Query operators
57
67
===============
58
68
Operators other than equality may also be used in queries; just attach the
@@ -68,6 +78,8 @@ Available operators are as follows:
68
78
* ``lte `` -- less than or equal to
69
79
* ``gt `` -- greater than
70
80
* ``gte `` -- greater than or equal to
81
+ * ``not `` -- negate a standard check, may be used before other operators (e.g.
82
+ ``Q(age__not__mod=5) ``)
71
83
* ``in `` -- value is in list (a list of values should be provided)
72
84
* ``nin `` -- value is not in list (a list of values should be provided)
73
85
* ``mod `` -- ``value % x == y ``, where ``x `` and ``y `` are two provided values
@@ -89,6 +101,27 @@ expressions:
89
101
90
102
.. versionadded :: 0.3
91
103
104
+ There are a few special operators for performing geographical queries, that
105
+ may used with :class: `~mongoengine.GeoPointField `\ s:
106
+
107
+ * ``within_distance `` -- provide a list containing a point and a maximum
108
+ distance (e.g. [(41.342, -87.653), 5])
109
+ * ``within_box `` -- filter documents to those within a given bounding box (e.g.
110
+ [(35.0, -125.0), (40.0, -100.0)])
111
+ * ``near `` -- order the documents by how close they are to a given point
112
+
113
+ .. versionadded :: 0.4
114
+
115
+ Querying by position
116
+ ====================
117
+ It is possible to query by position in a list by using a numerical value as a
118
+ query operator. So if you wanted to find all pages whose first tag was ``db ``,
119
+ you could use the following query::
120
+
121
+ BlogPost.objects(tags__0='db')
122
+
123
+ .. versionadded :: 0.4
124
+
92
125
Limiting and skipping results
93
126
=============================
94
127
Just as with traditional ORMs, you may limit the number of results returned, or
@@ -181,6 +214,22 @@ custom manager methods as you like::
181
214
assert len(BlogPost.objects) == 2
182
215
assert len(BlogPost.live_posts) == 1
183
216
217
+ Custom QuerySets
218
+ ================
219
+ Should you want to add custom methods for interacting with or filtering
220
+ documents, extending the :class: `~mongoengine.queryset.QuerySet ` class may be
221
+ the way to go. To use a custom :class: `~mongoengine.queryset.QuerySet ` class on
222
+ a document, set ``queryset_class `` to the custom class in a
223
+ :class: `~mongoengine.Document `\ s ``meta `` dictionary::
224
+
225
+ class AwesomerQuerySet(QuerySet):
226
+ pass
227
+
228
+ class Page(Document):
229
+ meta = {'queryset_class': AwesomerQuerySet}
230
+
231
+ .. versionadded :: 0.4
232
+
184
233
Aggregation
185
234
===========
186
235
MongoDB provides some aggregation methods out of the box, but there are not as
@@ -402,8 +451,10 @@ that you may use with these methods:
402
451
* ``pop `` -- remove the last item from a list
403
452
* ``push `` -- append a value to a list
404
453
* ``push_all `` -- append several values to a list
454
+ * ``pop `` -- remove the first or last element of a list
405
455
* ``pull `` -- remove a value from a list
406
456
* ``pull_all `` -- remove several values from a list
457
+ * ``add_to_set `` -- add value to a list only if its not in the list already
407
458
408
459
The syntax for atomic updates is similar to the querying syntax, but the
409
460
modifier comes before the field, not after it::
0 commit comments