【发布时间】:2018-03-08 16:00:48
【问题描述】:
我在名为 Resources 的 mongodb 表中有类似于以下的数据。
{
"_id":"testuser",
"_class":"com.Resources",
"allocations":[
{
"contractId":"5083",
"status":"UNKNOWN"
}
]
}
{
"_id":"testuser",
"_class":"com.Resources",
"allocations":[
{
"contractId":"5084",
"status":"Dead"
}
]
}
{
"_id":"testuser2",
"_class":"com.Resources",
"allocations":[
{
"contractId":"5085",
"status":"Live"
}
]
}
我想在 shell 中运行一个查询,该查询返回每个 _id 的所有 contractID 及其状态,这实际上是我在表中的 resourceID。格式应为“_id - contractId - status”。例如,当使用上述数据运行时,我们应该看到以下内容:
testuser - 5083 - UNKNOWN
testuser - 5084 - Dead
testuser2 - 5085 - Live
感谢任何帮助。
【问题讨论】:
标签: json database mongodb aggregate