0
我的MongoDB的文档是MongoDB中找到价值关键在嵌套数组
{
_id:'ghuvt6GYrs6Hhgts6uhg',
photos:[
{
"photoId":"1322",
"title":"Life is beautiful",
"score":"1331322"
},
{
"photoId":"1323",
"title":"Very Cute Dog",
"score":"1231726"
},
{
"photoId":"1324",
"title":"Funny Cat",
"score":"1246556"
},
{
...
...
...
}
.
.
.
.
.
]
}
我要实现的是,进去photos
阵列子阵列,其中photoId:"1323"
我可以
$doc_test = $collection_images->findone(
array("_id" => new MongoId('ghuvt6GYrs6Hhgts6uhg')),
array("photos" =>
array(
'$elemMatch' => array(
"photoId" => "1323"
)
)
)
);
在PHP中实现它
而到结果会像[JSON]
{
"photoId":"1323",
"title":"Very Cute Dog",
"score":"1231726"
}
但我想匹配子阵列的密钥(指数)值,因为这将是1
因为子阵列是第二从顶部在photos
阵列
请建议不使用溶液地图减少