Mongo DB交易查询
我正在尝试创建一个MongoDB查询,以查看哪些发票是付款。 I would like to add few things to the outcome like:
- virtualAmount : original amount - (sum of all creditnotes)
- total paid amount : sum of all transactions where delete is false
- paid (true/false) : if virtualAmount - total paid amount is 0
我创建了Mongo游乐场
- : 可能的?
- 使用组时如何仍然具有原始对象?
- 还可以用猫鼬创建这个结果吗?
I'm trying to create a mongodb query to see which invoices are paid or not. I would like to add few things to the outcome like:
- virtualAmount : original amount - (sum of all creditnotes)
- total paid amount : sum of all transactions where delete is false
- paid (true/false) : if virtualAmount - total paid amount is 0
I have created mongo playground:
https://mongoplayground.net/p/0OyK_bOZu9X
- Anyone know if this is possible?
- How to still have the original object when using group?
- Is it also possible to create this result with mongoose?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由$ Undind Array和$组组。
结果
编辑
或者没有小组
by $unwind array and $group it.
result
EDIT
or easy way without group