Slicing in mongoengine
I have a Thread document which has within it Comments, which are EmbeddedDocuments. I don't want to have all of the comments return at once, but instead display them ten at a time.
In PyMongo or with just MongoDB I know I could use the $slice operator, but I'm not sure of how to do this with mongoengine. If I do
Thread.objects.get(id=thread_id).comments[:10]
will it only fetch those ten from the datab开发者_JS百科ase?
Cheers!
Support has been added in the dev branch and will make the next release!
You can return only 10 comments by using the fields and slice method:
thread = Thread.objects.fields(slice__comments=10).get(id=thread_id)
精彩评论