【发布时间】:2018-08-17 15:16:24
【问题描述】:
所以我发现了类似的问题,但并没有完全回答我正在寻找的内容。如果这是重复的;请随时为我指出合适的地方。
我有一个集合,它是一些非常大的文档的“真实来源”。在进行主要分析之前,我想使用查询引擎进行一些预过滤。
查询 1:
仅检索 document.financials.entrycount $gte 4 的文档。所以基本上在一个文档中我有一个财务子文档。我想用这个作为过滤器。我只想返回条目数大于 4 的文档。
查询 2:
能够进行数学运算并将其与数字进行比较以进行检索。
例如:
(totalAssets + totalCash) / (totalDebt + totalLiabilities) < .5
这些数字在子文档中的位置。
终于可以把这些结合起来了。
以下是预计仅包含季度财务数据的示例文档。
{
"symbol": "AAWW",
"quarterly_financials": {
"2017-09-30": {
"cashChange": -106467000,
"cashFlow": 82299000,
"costOfRevenue": 439135000,
"currentAssets": 449776000,
"currentCash": 176280000,
"currentDebt": 196509000,
"grossProfit": 96613000,
"netIncome": -24162000,
"operatingExpense": 43690000,
"operatingGainsLosses": 378000,
"operatingIncome": 52923000,
"operatingRevenue": 535748000,
"researchAndDevelopment": None,
"shareholderEquity": 1575169000,
"totalAssets": 4687302000,
"totalCash": 175926000,
"totalDebt": 2105344000,
"totalLiabilities": None,
"totalRevenue": 535748000
},
"2017-12-31": {
"cashChange": 115584000,
"cashFlow": 136613000,
"costOfRevenue": 474565000,
"currentAssets": 587586000,
"currentCash": 291864000,
"currentDebt": 218013000,
"grossProfit": 153387000,
"netIncome": 209448000,
"operatingExpense": 46628000,
"operatingGainsLosses": -95000,
"operatingIncome": 106759000,
"operatingRevenue": 627952000,
"researchAndDevelopment": None,
"shareholderEquity": 1789856000,
"totalAssets": 4955462000,
"totalCash": 294413000,
"totalDebt": 2226999000,
"totalLiabilities": None,
"totalRevenue": 627952000
},
"2018-03-31": {
"cashChange": -161460000,
"cashFlow": 69125000,
"costOfRevenue": 498924000,
"currentAssets": 433193000,
"currentCash": 130404000,
"currentDebt": 223308000,
"grossProfit": 91090000,
"netIncome": 9612000,
"operatingExpense": 50521000,
"operatingGainsLosses": None,
"operatingIncome": 40569000,
"operatingRevenue": 590014000,
"researchAndDevelopment": None,
"shareholderEquity": 1792299000,
"totalAssets": 5016832000,
"totalCash": 136421000,
"totalDebt": 2270870000,
"totalLiabilities": None,
"totalRevenue": 590014000
},
"2018-06-30": {
"cashChange": 97525000,
"cashFlow": 106786000,
"costOfRevenue": 548491000,
"currentAssets": 565191000,
"currentCash": 227929000,
"currentDebt": 245322000,
"grossProfit": 117654000,
"netIncome": -21150000,
"operatingExpense": 47334000,
"operatingGainsLosses": None,
"operatingIncome": 70320000,
"operatingRevenue": 664531000,
"researchAndDevelopment": None,
"shareholderEquity": 1776073000,
"totalAssets": 5348343000,
"totalCash": 234280000,
"totalDebt": 2501488000,
"totalLiabilities": None,
"totalRevenue": 666145000
}
}
}
【问题讨论】:
标签: python mongodb mongodb-query aggregation-framework pymongo