为了账号安全,请及时绑定邮箱和手机立即绑定

关于mongodb的多个嵌套子文档同时group by

关于mongodb的多个嵌套子文档同时group by

慕后森 2019-05-25 15:03:34
现在有一个文档集合col,其中文档记录结构如下,集合当中有多个这样的文档记录:{"_id":1,"shares":[{"fundcode":"000001","lastshares":1230.20,"agencyno":"260","netno":"260"},{"fundcode":"000002","lastshares":213124.00,"agencyno":"469","netno":"001"},{"fundcode":"000003","lastshares":10000.80,"agencyno":"469","netno":"002"}],"trade":[{"fundcode":"000001","c_date":"20160412","agencyno":"260","netno":"260","bk_tradetype":"122","confirmbalance":1230.20,"cserialno":"10110000119601","status":"1"},{"fundcode":"000002","c_date":"20160506","agencyno":"469","netno":"001","bk_tradetype":"122","confirmbalance":213124.00,"cserialno":"10110000119602","status":"1"},{"fundcode":"000003","c_date":"20170507","agencyno":"469","netno":"002","bk_tradetype":"122","confirmbalance":10000.80,"netvalue":1.0000,"cserialno":"10110000119602","status":"1"}]}现在我要找到符合特定条件的记录,实现一个类似以下逻辑的SQL。我该怎么写mongodb的查询语句呢?select_idfromcolwherecol.shares.lastshares>1000andcol.trade.agencyno='469'groupby_idhavingcount(distinctcol.shares.fundcode)>2andcount(distinctcol.trade.fundcode)>2用一次$unwind还行,但连续使用$unwind(先shares,再confirm),再$match,再$group,再$match的逻辑不太正确,还请牛人指点,谢谢~
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 1431 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信