Note that there are some explanatory texts on larger screens.

plurals
  1. POMongo query inside Hashmap with unknown hash key
    primarykey
    data
    text
    <p><strong>Platform:</strong> MongoDB, Spring, SpringDataMongoDB</p> <p>I have a collection called "Encounter" with below structure</p> <p>Encounter:</p> <pre><code>{ "_id" : "49a0515b-e020-4e0d-aa6c-6f96bb867288", "_class" : "com.keype.hawk.health.emr.api.transaction.model.Encounter", "encounterTypeId" : "c4f657f0-015d-4b02-a216-f3beba2c64be", "visitId" : "8b4c48c6-d969-4926-8b8f-05d2f58491ae", "status" : "ACTIVE", "form" : { "_id" : "be3cddc5-4cec-4ce5-8592-72f1d7a0f093", "formCode" : "CBC", "fields" : { "dc" : { "label" : "DC", "name" : "tc", }, "tc" : { "label" : "TC", "name" : "tc", }, "notes" : { "label" : "Notes", "name" : "notes", } }, "notes" : "Blood Test", "dateCreated" : NumberLong("1376916746564"), "dateModified" : NumberLong("1376916746564"), "staffCreated" : 10013, "staffModified" : 10013 }, } </code></pre> <p>The element "<code>fields</code>" is represented using a Java Hashmap as:</p> <pre><code>protected LinkedHashMap&lt;String, Field&gt; fields; </code></pre> <p>The Key to the hashmap () is not fixed, but generated at run time.</p> <p>How do I query to get all documents in the collection where "label" = "TC"?</p> <p>It's not possible to query like <code>db.encounter.find({'form.fields.dc.label':'TC'})</code> because the element name 'dc' is NOT known. I want to skip that postion and the execute query, something like:</p> <pre><code>db.encounter.find({'form.fields.*.label':'TC'}); </code></pre> <p>Any ideas?</p> <p>Also, how do I best use indexes in this scenario?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload