php - 从 MongoDB 中的 Document (PHP) 中检索深度嵌套的子文档
问题描述
我有一个类似的集合:
{
'_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}
]
}
}
}
我正在尝试输出:
{
index: 21,
abc:22,
sim: [
{s_index:23},
{hyx:45}
]
}
但是使用以下查询:
$Result = $templates -> findOne(
[
'_id' => new \MongoDB\BSON\ObjectId("5bc74908f2377d746g1e9983")
],
['projection' => ['_id' => false, 'components.0' => true]]
);
我得到的输出为:
{
components:{
0: {
index: 21,
abc:22,
sim: [
{s_index:23},
{hyx:45}
]
}
}
}
有没有办法获得所需的输出?
我试图只检索 的值,component.0
但我得到了文档中的完整路径。
sim
是一个对象数组。如果我只想在sim
不是从组件到 sim 的路径中检索特定对象怎么办。这可以做到吗?
解决方案
推荐阅读
- php - Magento - getEmail() 在哪里定义?
- java - 防止 Spring Boot 在启动时调用 EC2MetadataUtils.getItems
- apache-spark - 从 Spark 中的 DataFrame 中过滤和选择数据
- mysql - “@”在这个位置是无效的输入 MySQL
- javascript - 设置 cookie 域
- delphi - System.Variants.NullStrictConvert 的范围
- docker - 是否可以编辑在 docker 容器上运行的图像内的文本文件?
- mysql - 如何在MYSQL中对列进行排序
- format - 以 ASCII 格式发送命令 STM32
- jquery - URL 中的问号未正确编码