add support for cursor.comment
This commit is contained in:
parent
088c5f49d9
commit
debc28a5cf
@ -933,6 +933,14 @@ class BaseQuerySet(object):
|
|||||||
queryset._ordering = queryset._get_order_by(keys)
|
queryset._ordering = queryset._get_order_by(keys)
|
||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
def comment(self, text):
|
||||||
|
"""Add a comment to the query.
|
||||||
|
|
||||||
|
See https://docs.mongodb.com/manual/reference/method/cursor.comment/#cursor.comment
|
||||||
|
for details.
|
||||||
|
"""
|
||||||
|
return self._chainable_method("comment", text)
|
||||||
|
|
||||||
def explain(self, format=False):
|
def explain(self, format=False):
|
||||||
"""Return an explain plan record for the
|
"""Return an explain plan record for the
|
||||||
:class:`~mongoengine.queryset.QuerySet`\ 's cursor.
|
:class:`~mongoengine.queryset.QuerySet`\ 's cursor.
|
||||||
|
@ -2199,6 +2199,22 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
a.author.name for a in Author.objects.order_by('-author__age')]
|
a.author.name for a in Author.objects.order_by('-author__age')]
|
||||||
self.assertEqual(names, ['User A', 'User B', 'User C'])
|
self.assertEqual(names, ['User A', 'User B', 'User C'])
|
||||||
|
|
||||||
|
def test_comment(self):
|
||||||
|
"""Make sure adding a comment to the query works."""
|
||||||
|
with db_ops_tracker() as q:
|
||||||
|
adult = (self.Person.objects.filter(age__gte=18)
|
||||||
|
.comment('looking for an adult')
|
||||||
|
.first())
|
||||||
|
ops = q.get_ops()
|
||||||
|
self.assertEqual(len(ops), 1)
|
||||||
|
op = ops[0]
|
||||||
|
self.assertEqual(op['query']['$query'], {
|
||||||
|
'_cls': 'Person',
|
||||||
|
'age': {'$gte': 18}
|
||||||
|
})
|
||||||
|
self.assertEqual(op['query']['$comment'],
|
||||||
|
'looking for an adult')
|
||||||
|
|
||||||
def test_map_reduce(self):
|
def test_map_reduce(self):
|
||||||
"""Ensure map/reduce is both mapping and reducing.
|
"""Ensure map/reduce is both mapping and reducing.
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user