I have a collection similar to this:
{
'_id': ObjectId("5bc74908f2377d746g1e9983"),
components:{
0: {
index: 21,
abc:22,
sim: [
{s_index:23},
{hyx:45}
]
},
1: {
index: 21,
abc:22,
sim: [
{s_index:23},
{hyx:45}
]
}
}
}
I am trying to output:
{
index: 21,
abc:22,
sim: [
{s_index:23},
{hyx:45}
]
}
But with the following query:
$Result = $templates -> findOne(
[
'_id' => new \MongoDB\BSON\ObjectId("5bc74908f2377d746g1e9983")
],
['projection' => ['_id' => false, 'components.0' => true]]
);
I am getting the output as:
{
components:{
0: {
index: 21,
abc:22,
sim: [
{s_index:23},
{hyx:45}
]
}
}
}
Is there any way to get the desired output? I am trying to retrieve just the value of component.0
but I am getting the complete path in the document.
sim
is an array of objects. What if I just want to retrieve a particular object in sim
not the path from components to sim. Can this be done?