如果得到以下数据库结构:
{ "_id" : "rv8MgKMB9qvrcoruW", "object" : "M5ZMiaqPQYP6Pv45y", "matches" : { "mbGLv9hiJJeyEcSoK" : "1", "hTcs5PYp5bXruZSTL" : "1" } }
{ "_id" : "2jksvGbg7fkguECRB", "object" : "M5ZMiaqPQYP6Pv45y", "matches" : { "mbGLv9hiJJeyEcSoK" : "2", "hTcs5PYp5bXruZSTL" : "2" } }
{ "_id" : "a5Ea5evtXkYrcjtLa", "object" : "M5ZMiaqPQYP6Pv45y", "matches" : { "JZKoX3B8gqiwotphb" : "3", "hTcs5PYp5bXruZSTL" : "3" } }
{ "_id" : "RsLhwDS5ERYxERAjX", "object" : "M5ZMiaqPQYP6Pv45y", "matches" : { "mbGLv9hiJJeyEcSoK" : "4", "JZKoX3B8gqiwotphb" : "4" } }
我喜欢在匹配中获取具有特定对象和特定键值对的数据集。
所以例如:我喜欢获取以下数据集:“object”:“M5ZMiaqPQYP6Pv45y”以及哪里存在字典集“JZKoX3B8gqiwotphb”:“3”。
所以在这种情况下,输出应该是:
{ "_id" : "a5Ea5evtXkYrcjtLa", "object" : "M5ZMiaqPQYP6Pv45y", "matches" : { "JZKoX3B8gqiwotphb" : "3", "hTcs5PYp5bXruZSTL" : "3" } }
我已经尝试了数百种组合,但我目前陷入了困境:
db.Matches.find ({ object: 'M5ZMiaqPQYP6Pv45y', matches: { mbGLv9hiJJeyEcSoK: { '$exists': true, $in: '3' } } })