聚合命令的PHP MongoDB管理器异常:“无法从服务器解码文档。”

时间:2017-03-29 14:59:16

标签: php mongodb aggregation-framework

我的样本集:

{
    "_id" : ObjectId("58dbc09b19d7a17e44201982"),
    "process_id" : "2-1490770330177",
    "contacts" : [
        {
            "party_id" : 6636,
            "completed" : true,
            "kind" : 1
        },
        {
            "party_id" : 139611,
            "completed" : true,
            "kind" : 1
        },
        {
            "party_id" : 32609,
            "completed" : true,
            "kind" : 1
        },

        {
            "party_id" : 49520,
            "completed" : false,
            "kind" : 1
        },
        {
            "party_id" : 204031,
            "completed" : false,
            "kind" : 1
        },
        {
            "party_id" : 204379,
            "completed" : false,
            "kind" : 1
        }
    ],
    "tags" : [
        1277
    ]
}

当我使用RoboMongo通过followig查询测试此文档时:

db.getCollection('BatchTag').aggregate(
                        {'$match':{"process_id":'2-1490770330177'}},
                        {'$unwind':'$contacts'},
                        {'$match':{'contacts.completed':false}},
                        {'$group':{_id:'$_id','contacts':{'$push':'$contacts'}}}
    )

我收到了这个结果。

{
    "_id" : ObjectId("58dbc09b19d7a17e44201982"),
    "contacts" : [
        {
            "party_id" : 49520,
            "completed" : false,
            "kind" : 1
        },
        {
            "party_id" : 204031,
            "completed" : false,
            "kind" : 1
        },
        {
            "party_id" : 204379,
            "completed" : false,
            "kind" : 1
        }
    ]
}

Bu当我在PHP上执行一些查询时。我收到了“无法从服务器解码文档。”异常。 我的PHP代码在这里:

            $command = new Command([
                "aggregate"=>"BatchTag",
                "pipeline" => [
                    ['$match'=>["process_id"=>$processUID]],
                    ['$unwind'=>'$contacts'],
                    ['$match'=>['contacts.completed'=>false]],
                    ['$group'=>['_id'=>'$_id','contacts'=>['$push'=>'$contacts']]]
                ]
            ]);
            $rows = $this->getMongoManager()->executeCommand($this->container->getParameter("mongodb_db_name").".BatchTag",$command)->toArray();

我不明白,有什么不对!

1 个答案:

答案 0 :(得分:2)

您正在将集合名称传递给executeCommand

您应该只传递db name作为function sheetchanger() { var ss = SpreadsheetApp.getActiveSpreadsheet(); var cell = ss.getRange("Lookup!B5"); ss.setActiveSheet(cell) obj已经有集合名称。

尝试类似

的内容
command