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
usersarray that has all the7k DBRefsvalues returned bymongodb.You need to include a
projectionoperation to just select the first10elements in theusersarray.The syntax in
MongoEngine: