【发布时间】:2018-02-21 00:37:29
【问题描述】:
我得到了一个包含以下格式数据的大数组:
{
"application": "myapp",
"buildSystem": {
"counter": 2361.1,
"hostname": "host.com",
"jobName": "job_name",
"label": "2361",
"systemType": "sys"
},
"creationTime": 1517420374748,
"id": "123",
"stack": "OTHER",
"testStatus": "PASSED",
"testSuites": [
{
"errors": 0,
"failures": 0,
"hostname": "some_host",
"properties": [
{
"name": "some_name",
"value": "UnicodeLittle"
},
<MANY MORE PROPERTIES>,
{
"name": "sun",
"value": ""
}
],
"skipped": 0,
"systemError": "",
"systemOut": "",
"testCases": [
{
"classname": "IdTest",
"name": "has correct representation",
"status": "PASSED",
"time": "0.001"
},
<MANY MORE TEST CASES>,
{
"classname": "IdTest",
"name": "normalized values",
"status": "PASSED",
"time": "0.001"
}
],
"tests": 8,
"time": 0.005,
"timestamp": "2018-01-31T17:35:15",
"title": "IdTest"
}
<MANY MORE TEST SUITES >,
]}
我可以用大数据区分三个主要结构:TestSuites、Properties 和 TestCases。我的任务是对每个 TestSuite 的所有时间求和,以便获得测试的总持续时间。由于属性和 TestCases 很大,因此无法完成查询。我只想从 TestSuites 中选择“时间”值,但它与我的查询中的 TestCases 的“时间”有点冲突:
db.my_tests.find(
{
application: application,
creationTime:{
$gte: start_date.valueOf(),
$lte: end_date.valueOf()
}
},
{
application: 1,
creationTime: 1,
buildSystem: 1,
"testSuites.time": 1,
_id:1
}
)
是否可以仅从 TestSuites 中投影“时间”属性而不加载整个架构?我已经尝试过 testSuites: 1, testSuites.$.time: 1 没有成功。请注意,TestSuites 是一个包含一个元素和字典的数组。
我已经检查过这个类似的帖子,但没有成功: Mongodb update the specific element from subarray
【问题讨论】:
-
为什么是
标签? -
抱歉,这无关紧要
-
docs.mongodb.com/manual/reference/operator/aggregation/project 你可以使用 $project 来做这个。
-
已经尝试过,请参阅下面的评论,因为 TestSuites 是一个数组,所以不起作用。
标签: mongodb