title: Mongo query for value in an object with any key
body: <p>Supposing we have documents in a Mongo collection with the following format:</p>
  <pre><code>{
      &quot;_id&quot; : &quot;5fb3c5ce9997c61e15a9108c&quot;,
      &quot;stages&quot; : {
            &quot;stage1&quot; : {
                &quot;type&quot; : &quot;RandomType&quot;
            },
            &quot;stage2&quot; : {
                &quot;type&quot; : &quot;RandomType2&quot;
            },
            &quot;arbitaryStage&quot; : {
                &quot;type&quot; : &quot;RandomType3&quot;
            },
            // Possibly many other stages
      },
      // Fields omitted
  }
  </code></pre>
  <p>How can I query a collection of such documents where any <code>stages.X.type</code> is equal to a predefined value? My application doesn't know what X is and doesn't care about it, it should only know that the type of at least one of the stages is equal to a given value. I am trying to do that in Morphia however plain JS would guide me if that's possible to do with the given data format.</p>
  <p>For reference the Class from which this entity is originated from is the following</p>
  <pre><code>@Entity(value = &quot;stages_collection&quot;, noClassnameStored = true)
  public class StackOverflowQ {
      @Id
      private ObjectId id;
      @Embedded
      private Map&lt;String, Stage&gt; stages;
      // Rest of fields/setters/getters omitted
  }
  
  public class Stage {
      private String type;
      // Rest of fields/setters/getters omitted
  }
  </code></pre>