I have combine the two columns into single columns for this using below one.
db.test.aggregate([{ $project: {category: ['$category1', '$category2'] } } ]).pretty();
It return perfect results in terminal, but doctrine it is not working?
$builder->project()->includeFields(['category'])->excludeIdField(['_id']);
It returns results as empty array of values.
{
"_id" : ObjectId("5c7cf5b4362a3134068b633d"),
"category" : [
"test1",
"test2"
]
}
{
"_id" : ObjectId("5c7cf5b4362a3134068b633e"),
"category" : [
"test1",
"test4"
]
}
Those two $project stages are completely different, as you can see when evaluating the result of $builder->getPipeline(). The ODM example you posted evaluates to this stage:
{
$project: {
_id: false,
category: true
}
}
If you were to reproduce the $project stage from your MongoDB shell example, it would look like this:
$builder->project()
->field('category')
->expression(['$category1', '$category2']);
@alcaeus Perfect...It is works...Thanks for time.
Most helpful comment
Those two
$projectstages are completely different, as you can see when evaluating the result of$builder->getPipeline(). The ODM example you posted evaluates to this stage:If you were to reproduce the
$projectstage from your MongoDB shell example, it would look like this: