将MongoDB查询转换为PHP

将MongoDB查询转换为PHP,php,mongodb,Php,Mongodb,第一个查询在我在Robomongo运行时起作用。但是,我在将其转换为PHP时遇到了困难 我已经包括了更新版本,如果我遗漏了什么,请告诉我 这很有效(MongoDB查询) 这不起作用(翻译成PHP) 更新 $collection -> find( array('_id' => new MongoId($id)), array( 'statuses' => array( $elemMatch: (

第一个查询在我在Robomongo运行时起作用。但是,我在将其转换为PHP时遇到了困难

我已经包括了更新版本,如果我遗漏了什么,请告诉我

这很有效(MongoDB查询)

这不起作用(翻译成PHP)

更新

$collection -> find(
    array('_id' => new MongoId($id)),
    array(
        'statuses' => array(
            $elemMatch: (
                id: $tweetID['id']
            )
        )
    )
);
数组如下所示:

Array
(
    [_id] => MongoId Object
    (
        [$id] => 123
    )

    [statuses] => Array
    (
        [0] => Array
            (
            [id] => 321
            [text] => Tweet no 1
            )
        [1] => Array
            (
            [id] => 322
            [text] => Tweet no 2
            )
        [2] => Array
            (
            [id] => 323
            [text] => Tweet no 3
            )
    )
)
您必须使用冒号(:)而不是assingment(>)。在mongodb中,每个花括号将在php中仅视为数组。希望您得到这个答案

您必须使用冒号(:)而不是assingment(>)。在mongodb中,每个花括号将在php中仅视为数组。希望您得到这个答案

$collection -> find(
    array('_id' => new MongoId($id)),
    array(
        'statuses' => array(
            $elemMatch: (
                id: $tweetID['id']
            )
        )
    )
);
Array
(
    [_id] => MongoId Object
    (
        [$id] => 123
    )

    [statuses] => Array
    (
        [0] => Array
            (
            [id] => 321
            [text] => Tweet no 1
            )
        [1] => Array
            (
            [id] => 322
            [text] => Tweet no 2
            )
        [2] => Array
            (
            [id] => 323
            [text] => Tweet no 3
            )
    )
)
$collection->find(
    array('_id' => new MongoId($id)),
    array(
        'statuses' => array(
            '$elemMatch' => array(
                'id'=>$tweetID['id']
            )
        )
    )
);