【发布时间】:2018-03-22 14:13:33
【问题描述】:
我最近开始在 Mongodb 中为 POC 工作。我在下面有一个 json 集合
db.ccpsample.insertMany([
{
"ccp_id":1,
"period":601,
"sales":100.00
},
{
"ccp_id":1,
"period":602,
"growth":2.0,
"sales":"NULL" ##sales=100.00*(1+(2.0/100)) -- 100.00 comes from(ccp_id:1 and period=601)
},
{
"ccp_id":1,
"period":603,
"growth":3.0,
"sales":"NULL" ##sales=100.00*(1+(2.0/100))**(1+(3.0/100))-- 100.00 comes from(ccp_id:1 and period=601) 2.0 comes from (ccp_id:2 and period=602)
},
{
"ccp_id":2,
"period":601,
"sales":200.00
},
{
"ccp_id":2,
"period":602,
"growth":2.0,
"sales":"NULL" ##sales=200.00*(1+(2.0/100))
},
{
"ccp_id":2,
"period":603,
"growth":3.0,
"sales":"NULL" ##same like above
}
])
并且我需要使用上面的文档来计算具有 NULL 的销售字段,匹配条件的 ccp_id 应该相同,期间字段应该等于 601。我添加了一行来演示上面集合本身中销售字段的计算。我尝试使用 $graphlookup 但没有运气。你们可以帮助或建议一些方法吗?
【问题讨论】:
-
能否提供
sales的公式?因为这些例子没有多大帮助。
标签: mongodb calculation