I have a document with around 7k DBRefs in one field to other objects. I want to limit the number of the objects coming back when I query the DBRef field but I cannot find an obvious way of doing it.
project = Project.objects.find({'id': 1})
users = project.users[:10]
On line 2 MongoEngine performs a query to retrieve ALL the users not just the first 10. What can I do to limit the query to only retrieve the first 10?
This operation is a client side operation, which is performed on the
users
array that has all the7k DBRefs
values returned bymongodb
.You need to include a
projection
operation to just select the first10
elements in theusers
array.The syntax in
MongoEngine
: