大橙子网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

MongoDB中怎么实现分页显示

MongoDB中怎么实现分页显示,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

创新互联建站从2013年开始,先为伊春等服务建站,伊春等地企业,进行企业商务咨询服务。为伊春企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

在MongoDB里面的数据分页显示也是符合大数据要求的操作函数:
skip(n):表示跨过多少数据行;
limit(n):取出的数据行的个数限制。

范例:分页显示(第一页,skip(0)、limit(5))
> db.emp.find().skip(0).limit(5).sort({"age":-1}).pretty();
{
        "_id" : ObjectId("599108423268c8e84253be2c"),
        "name" : "郑七",
        "sex" : "女",
        "age" : 50,
        "sal" : 4700,
        "loc" : "成都"
}
{
        "_id" : ObjectId("599108423268c8e84253be28"),
        "name" : "孙三",
        "sex" : "男",
        "age" : 40,
        "sal" : 2000,
        "loc" : "深圳"
}
{
        "_id" : ObjectId("599148bf0184ff511bf02b95"),
        "name" : "林E",
        "sex" : "男",
        "age" : 40,
        "sal" : 8000,
        "loc" : "北京",
        "course" : [
                "语文",
                "政治"
        ],
        "parents" : [
                {
                        "name" : "林E父亲",
                        "age" : 70,
                        "job" : "工人"
                },
                {
                        "name" : "林E母亲",
                        "age" : 68,
                        "job" : "局长"
                }
        ]
}
{
        "_id" : ObjectId("599108433268c8e84253be2d"),
        "name" : "王八",
        "sex" : "男",
        "age" : 35,
        "sal" : 8000,
        "loc" : "北京"
}
{
        "_id" : ObjectId("599129a00184ff511bf02b87"),
        "name" : "刘A",
        "sex" : "男",
        "age" : 35,
        "sal" : 8000,
        "loc" : "北京",
        "course" : [
                "语文",
                "数学",
                "英语",
                "音乐",
                "政治"
        ]
}

范例:分页显示(第二页,skip(5)、limit(5))
> db.emp.find().skip(5).limit(5).sort({"age":-1}).pretty();
{
        "_id" : ObjectId("599129a00184ff511bf02b88"),
        "name" : "刘B",
        "sex" : "男",
        "age" : 35,
        "sal" : 8000,
        "loc" : "北京",
        "course" : [
                "语文",
                "数学"
        ]
}
{
        "_id" : ObjectId("599129a00184ff511bf02b89"),
        "name" : "刘C",
        "sex" : "男",
        "age" : 35,
        "sal" : 8000,
        "loc" : "北京",
        "course" : [
                "语文",
                "数学",
                "英语"
        ]
}
{
        "_id" : ObjectId("599129a00184ff511bf02b8a"),
        "name" : "刘D",
        "sex" : "男",
        "age" : 35,
        "sal" : 8000,
        "loc" : "北京",
        "course" : [
                "语文",
                "数学",
                "政治"
        ]
}
{
        "_id" : ObjectId("599129a20184ff511bf02b8b"),
        "name" : "刘E",
        "sex" : "男",
        "age" : 35,
        "sal" : 8000,
        "loc" : "北京",
        "course" : [
                "语文",
                "政治"
        ]
}
{
        "_id" : ObjectId("599148bd0184ff511bf02b93"),
        "name" : "林C",
        "sex" : "男",
        "age" : 35,
        "sal" : 8000,
        "loc" : "北京",
        "course" : [
                "语文",
                "数学",
                "英语"
        ],
        "parents" : [
                {
                        "name" : "林C父亲",
                        "age" : 60,
                        "job" : "工人"
                },
                {
                        "name" : "林C母亲",
                        "age" : 59,
                        "job" : "职员"
                }
        ]
}


看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。


文章名称:MongoDB中怎么实现分页显示
网址分享:http://dzwzjz.com/article/goiejo.html
在线咨询
服务热线
服务热线:028-86922220
TOP