title: Pymongo query on "subdocuments"
body: <p>Each instance of a collection called <code>groups</code> has a field called <code>actives</code>, which is a list of "subdocuments", i.e. things of the form {keys: values}. One field (key) of the subdocuments is <code>id_</code>, which is a string.</p>
  
  <p>If I take the set of all subdocuments present in all the instances of <code>groups</code>, then there won't be 2 equal <code>id_</code>, i.e. <code>id_</code> identifies uniquely each subdocument. However, I get a new subdocument. I need to run a program with the subdocument's id that will go to a website and extract info about the subdocument. Within this info I find the group that the subdocument belongs to. However, I don't want to run this program if I already have some subdocument, in some instance of <code>groups</code> with the same <code>id_</code> as the "new" subdocument.</p>
  
  <p>How can I list the ids of all the subdocuments of all the documents (or instances of <code>groups</code>)?</p>
  
  <p>Edit:</p>
  
  <p>Suppose that the documents of the DB groups are:</p>
  
  <pre><code>doc1: {"neighbourhood": "n1", "actives": [{"id_": "MHTEQ", "info": "a_long_string"}, {"id_": "PNPQA", "info": "a_long_string"}]}
  
  doc2: {"neighbourhood": "n2", "actives": [{"id_": "MERVX", "info": "a_long_string"}, {"id_": "ZDKJW", "info": "a_long_string"}]}
  </code></pre>
  
  <p>What I want to do is to list all the <code>"id_"</code>, i.e.</p>
  
  <pre><code>def list_ids(groups):
      do_sth_with_groups
      return a_list
  
  print(list_ids(groups))
  
  output: ["MHTEQ", "PNPQA", "MERVX", "ZDKJW"]
  </code></pre>