在mongodb中嵌入注释分页 [英] Embeded comment paging in mongodb

查看:125
本文介绍了在mongodb中嵌入注释分页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个集合用于存储文章与它的注释嵌入,当从数据库检索数据,我会得到一个完整的评论列表的文章对象,支持有很多评论,所以这可能是一个问题加载效率,我如何处理这个通过分页评论?我必须使用一个单独的集合来评论吗?还是什么?

if I got a collection for storing Articles with it's Comments embedded, when retriving data from db, I will get a Article object with a completely Comment list, support there are a lot of comments, so this could be a problem of loading efficience, how can I handler this by paging Comments? do I have to use a seperate collection for Comments? or what else? thanx in advance.

推荐答案

您正在寻找 $ slice 运算符。

要通过分页检索评论,您需要如下代码:

To retrieve comments by paging you need code like this:

db.articles.find({}, {comments:{$slice: [20, 10]}}) // skip 20, limit 10 

此操作将返回仅包含切片注释的文章。 )

This operation will return articles with only sliced comments. )

这篇关于在mongodb中嵌入注释分页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆