开发者

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜