title: MongoDB find query in list of dictionaries
body: <p>I have a collection as below</p>
  
  <pre><code>            {
              "state" : "VIC",
              "sites" : 
              [
                  {
                      "name" : "VIC01",
                      "pes" :
                          [
                              {
                                  "id" : "1",
                                  "longname" : "rdnvej300exh0443",
                                  "shortname" : "RVE4-E-043",
                                  "location" : "Exhibition"
                              },
                              {
                                  "id" : "2",
                                  "longname" : "rdnvej160pee0343",
                                  "shortname" : "RV3W-E-043",
                                  "location" : "Windsor"
                              },
                              {
                                  "id" : "3",
                                  "location" : "my home"
                              }
                          ],
                      "partners" :
                          [
                              {
                                  "id" : "REACH",
                                  "fnns" : ["N54321R","N24686R","N46818R","N10461R"]
                              },
                              {
                                  "id" : "NCS_CORE",
                                  "fnns" : [ "N54320R","N71311R","N35797R","N57919R"]
                              }
                          ]           
                  },
  
                  {
                      "name" : "CLAYTON",
                      "pes" :
                          [
                              {
                                  "id" : "1",
                                  "longname" : "rdnvej1822da0o43",
                                  "shortname" : "RVCZ-E-043",
                                  "location" : "Clayton"
                              },
                              {
                                  "id" : "2",
                                  "longname" : "rdnvej1822da0o44",
                                  "shortname" : "RVCZ-E-044",
                                  "location" : "Clayton"
                              }
                          ],
                      "partners" :
                          [
                              {
                                  "id" : "NCS_CORE",
                                  "fnns" : ["N54331R","N24686R","N46818R","N10461R"]
                              },
                              {
                                  "id" : "NCS_CLAYTON_OPS2",
                                  "fnns" : [ "N54321R","N71311R","N35797R","N57919R"]
                              }
                          ]
                  }
              ]
              }
  </code></pre>
  
  <p>I am trying to retrieve </p>
  
  <blockquote>
    <p>{state, sites.name,sites.partners.id}</p>
  </blockquote>
  
  <p>from all the documents having "N54321R" in "fnns" list.</p>
  
  <p>I tried below queries but for the above it is giving all sites.partners.id.</p>
  
  <pre><code>1. db.topology.find( {"sites.partners.fnns" : { "$elemMatch" : { "$eq" : "N54321R" } } }, {"state" : 1 , "sites.name" : 1, "sites.partners.id" : 1 , "sites.partners.fnns" : 1} )
  
  
  2. db.topology.find( {"sites.partners.fnns" : { $in : ["N54321R"] } }, {"state" : 1 , "sites.name" : 1, "sites.partners.id" : 1 , "sites.partners.fnns" : 1} )
  
  
  3. db.topology.find( {"sites.partners.fnns" : "N54321R"} , {"state" : 1 , "sites.name" : 1, "sites.partners.id" : 1 , "sites.partners.fnns" : 1} )
  </code></pre>
  
  <p>Correct output should be (just showing sites.partners.id)</p>
  
  <pre><code>{ REACH , NCS_CLAYTON_OPS2 }
  </code></pre>
  
  <p>but it is giving all sites.partners.id i.e.</p>
  
  <pre><code>{ REACH , NCS_CORE , NCS_CORE , NCS_CLAYTON_OPS2 }
  </code></pre>
  
  <p>What should I modify in the query to achieve the results? </p>
  
  <p>If schema change required then please tell me what should be the correct schema?</p>
  
  <p>Thanks.</p>