Morphia query by referenced object

331 Views Asked by At

I have an object like below

class Test1 {

  @Id
  var id: ObjectId = _

  @Reference
  var referrenced: Referrenced = _

  ...
}

And referenced object

Class Referenced {

  @Id
  var id: ObjectId = _

  var when: Date = _
}

How can I find all Test1 object that has Referenced object when between times?

1

There are 1 best solutions below

1
On

You can use $lookup if you're doing an aggregation MongoDB 3.4. Otherwise, Mongo's query language doesn't support a join so you'd have to first query for all the ID values for Referenced instances between those times and then query for Test1 instances with those ID values.