Home >Backend Development >PHP Tutorial >如下数据格式,如何获取mongodb若干条数据

如下数据格式,如何获取mongodb若干条数据

WBOY
WBOYOriginal
2016-06-06 20:45:061018browse

<code>{
    id:1,
    username:'test',
    list:
    [
        {
            name:'t1'
        },
        {
           name:'t2'
        }
    ]
}
</code>

可以直接获取list分段查询吗?
比如一页显示一条,第一页显示[{name:'t1'}] 第二页显示[{name:'t2'}],这样子

回复内容:

<code>{
    id:1,
    username:'test',
    list:
    [
        {
            name:'t1'
        },
        {
           name:'t2'
        }
    ]
}
</code>

可以直接获取list分段查询吗?
比如一页显示一条,第一页显示[{name:'t1'}] 第二页显示[{name:'t2'}],这样子

可以用MongoDB的聚合框架

<code class="lang-javascript">db.test.aggregate([ {$match: {id:1}},  {$unwind: "$list"}, {$sort:{'list.name':1}}, {$skip:5}, {$limit: 5}]);   // 取得list下面从第6个到第10个
</code>

你想问什么。。。。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn