Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerying based on available partial data of nested document (in morphia, mongoDB)
    text
    copied!<p>Document structure (just for illustration)</p> <p>Employee</p> <pre><code>{ name : "..", age : .., addresses [ { "street":"...", "country":{ name:"..", continent:"..", Galaxy:".." } } ], company:".." } </code></pre> <p>Query -</p> <p>I have just Addresses -> street (type String) and Addresses -> country -> name (type String). And i want to get all employees that match this criteria.</p> <pre><code>Address a1 = new Address(); a1.setStreet("bla bla"); Country c = new Country(); c.setName("sth"); a1.setCountry(c); Query&lt;Employee&gt; q = ds.createQuery(Employee.class).field("addresses").hasThisElement(a1) </code></pre> <p>DOESN'T fetch results (when actually there is a real match). Looks like its because of partial "Country" document match. If i populate <em>all</em> fields of Country its getting results as expected. </p> <p>Question #1 : Any workaround for above? </p> <p>Question #2 : Address is an array and i can get multiple (address#street, country#name) pairs and again i want the list of employees that match given pairs. Something like:</p> <pre><code>Query&lt;Employee&gt; q = ds.createQuery(Employee.class).field("addresses").hasThisElement(a1).field("addresses").hasThisElement(a2).field(..) // and so on </code></pre> <p>Note: i can breakdown address match something like this</p> <pre><code>Address a = new Address(); a.setStreet("bla bla"); q.createQuery(Employee.class).field("addresses").hasThisElement(a).field("addresses.country.name").equal("hoo"); </code></pre> <p>BUT this will match Employee where street="bla bla" and country.name!="hoo" in address#1 and street!="bla bla" and country.name="hoo" in address #2. You get the point. I don't want such Employees to be returned.</p> <p>Please let me know if this is possible. Thanks much.</p>
 

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