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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:45:06
Original
1090 people have browsed it

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

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

回复内容:

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

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

可以用MongoDB的聚合框架

db.test.aggregate([ {$match: {id:1}},  {$unwind: "$list"}, {$sort:{'list.name':1}}, {$skip:5}, {$limit: 5}]);   // 取得list下面从第6个到第10个
Copy after login

你想问什么。。。。

Related labels:
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template