1

My Sample collection:

{
    "_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
    ]
}

And When I test this document with RoboMongo via followig query:

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

I've received this result.

{
    "_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 When I execute some query on PHP. I've received "Failed to decode document from the server." exception. My PHP code is here:

            $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();

I don't understand, what is wrong!

1 Answer 1

2

You are passing the collection name too to the executeCommand.

You should only pass db name as command obj already has collection name.

Try something like

$rows = $this->getMongoManager()->executeCommand($this->container->getParameter("mongodb_db_name"),$command)->toArray();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.