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

MongoDB java 查询嵌套JSON数据?

MongoDB java 查询嵌套JSON数据?

慕尼黑的夜晚无繁华 2019-02-28 04:08:20
如何在java中查询存在MongoDB里的嵌套json格式的数据?这是我的json数据:{ "_id" : ObjectId("59eac603b2921c583a1a38c1"), "mj1" : { "source" : 104963,"dj":"mih", "number" : 3, "target" : 100322,"weights" : 122 }, "mj2" : { "source" : 109601,"dj":"mih", "number" : 4, "target" : 105710,"weights" : 10 } }{ "_id" : ObjectId("59eac6b7b2921c583a1a38cd"), "mj1" : [ { "source" : 104963,"dj":"mih","number" : 3, "target" : 100322,"weights" : 1022 },"mj2" : { "source" : 109601,"dj":"mih", "number" : 4, "target" : 105710,"weights" : 2 } ] }我先用了这句话( db.mjj.find({"mjj1":{"$ne" : null,$exists : true}}))查询,可以得到如上结果,但是,我只想查询"source","number","target",这三样,该如何编写程序?CMD的命令和JAVA的命令回答都可以。
查看完整描述

1 回答

?
ibeautiful

TA贡献1993条经验 获得超5个赞

db.mjj.find({"$and": [{mj1.source: 12345}, {mj1.number: 22345}, {mj1.target: 32345}]}
查看完整回答
反对 回复 2019-03-01
  • 1 回答
  • 0 关注
  • 2702 浏览

添加回答

举报

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