Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

335
Visualizações
$pipeline is not a list (unexpected index: "$group") in Laravel

When the below query is run the results are displayed in mongo shell.

Sample Records

{
    "_id" : ObjectId("587e21df6e79d255011a9c6a"),
    "vendor_id" : "101",
    "subscription_id" : 14,
    "created_at" : ISODate("2017-01-17T13:53:35.272Z")
}
{
    "_id" : ObjectId("587e21df6e79d255011a9c6c"),
    "vendor_id" : "102",
    "subscription_id" : 14,
    "created_at" : ISODate("2017-01-17T13:56:35.272Z")
}

Query

db.user_config.aggregate({$group: 
{
    _id : "$subscription_id", 
    list: 
    { 
        $push:  
        { 
            _id: "$_id", 
            vendor_id: "$vendor_id"
        } 
     }
}})

Results

/* 1 */
{
    "result" : [ 
        {
            "_id" : 14,
            "list" : [ 
                {
                    "_id" : ObjectId("587e21df6e79d255011a9c6a"),
                    "vendor_id" : "user_101"
                }, 
                {
                    "_id" : ObjectId("587e21df6e79d255011a9c6b"),
                    "vendor_id" : "user_101"
                }
            ]
        }
    ],
    "ok" : 1.0000000000000000
}

But when same thing is done through laravel the following error occurs. $pipeline is not a list (unexpected index: "$group")

Below is the laravel code

$configuration_list = UserConfig::raw()->aggregate([
            '$group' => [
                    '_id'    => '$subscription_id',
                    'list'  => ['$push' => 
                     ['_id' => '$_id', 'vendor_id' => '$vendor_id']]
                ]
            ]
        );

Can someone please help me solve this issue..

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Wrap the aggregation pipeline steps in an array:

$pipeline = [
    [
        '$group' => [
            '_id' => '$subscription_id',
            'list' => [
                '$push' => [
                    '_id' => '$_id', 
                    'vendor_id' => '$vendor_id'
                ]
            ]
        ]
    ]
];
$configuration_list = UserConfig::raw()->aggregate($pipeline);
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda