PHP mongodb新驱动程序片(init,limit)嵌套数组

时间:2016-09-11 16:42:30

标签: php mongodb limit slice database

我在MongoDB中有这个集合

{"name": "x", password: "x" recipes: 
[{title: eggs, ...},{title: "pizza" ...}], name: "y", password: "y" recipes: [...]}

我正在使用新的php mongodriver 1.0

我想获得用户过滤器的所有食谱。 但有一个限制和初始化。

例如显示从3º配方开始的2个食谱:

[0,1,2,3,4,5]

显示

[3,4]

我正在尝试这个

$recipes= $db->users->find([],
    [
        "projection"=> ['recipes'=> ['$slice' => [3,2]]]
    ]);

但不起作用。

然而,此工作限制了配方显示但whitout开始过滤器

$recipes= $db->users->find([],
        [
            "projection"=> ['recipes'=> ['$slice' => 2]]
        ]);

这个节目有点像这样

[0,1] of [0,1,2,3,4,5]

请帮帮我。

1 个答案:

答案 0 :(得分:0)

尝试:

$recipes = db->users->find(array(), array('recipes' => array( '$slice' => [3,2] ) ) );

Mongo shell:

db.users.find( {}, { recipes: { $slice: [3,2] } } );
相关问题