这是我在文本模式下的示例MongoDB
我想检索每个用户的数据 . 我也想要_id因为在一个完整的文档中它有几个具有相似结构的_id .
我尝试使用unwind运算符,因为该对象包含嵌套数组,如下所示:
db.getCollection('topic_stats_2').aggregate([{ $unwind : "$usages.type.users.text" }, { $unwind : "$usages.type.users.stats.xyz1" }, { $unwind : "$usages.type.users.stats.xyz2" }, { $unwind : "$usages.type.users.stats.xyz3" }, { $unwind : "$usages.type.users.xyz4" }, { $unwind : "$usages.type.users.xyz5" }])
但它没有结果 .
我希望结果以表格格式这样 . 我知道该表将包含大量冗余数据 . 但这就是我想要的 .
_id | count | xyz4 | xyz5 | xyz1 | xyz2 | xyz3 | text | type |
| | | | | | | | |
| | | | | | | | |
/* 1 */
{
"_id" : “photo",
"count" : 236,
"usages" : [
{
"type" : 1,
"users" : [
{
"text