Morphia: Search for null values in a list of embedded objects

I have a list of embedded entities: @Embedded private List embedded = new ArrayList(); In this list, I want to search for any embedded entity which has a specific attribute (let's call it ``foo``), but not another one (``bar``). So ``foo`` should be non-null and ``bar`` null in Java / inexistant in MongoDB. I tried the following code (I do have the UUID of the ``Entity`` containing the list): Query query = mongoDataStore.find(Entity.class).field("uuid").equal(uuid) .field("embedded.foo").exists() .field("embedded.bar").doesNotExist(); This works correctly if the list is empty or has a single entry (where ``foo`` has a value and ``bar`` does not yet exist). But as soon as any ``bar`` attribute has a value, the query returns the wrong result. So I'm looking for a query, which iterates through all the embedded entities and fires on any missing ``bar``. Is that possible? Example data: // the query does not pick up the entity as it doesn't have a foo - // that's what I want { uuid: "...", [ { embedded: } ] } // the query picks up the entity as there is a foo but no bar - // that's what I want { uuid: "...", [ { embedded: { foo: date } } ] } // the query does not pick up the entity - that's not what I want // as one foo has a value and its bar doesn't { uuid: "...", [ { embedded: { foo: date, bar: date } }, { embedded: { foo: date } } ] } PS: I get the same result with ``.field("embedded.bar").hasThisOne(null)``. PPS: Manually iterating through the list elements is not really an option, as I want to use the query for an update operation. PPS: I think this is a bug in Morphia - see my answer below ([https://stackoverflow.com/a/9705175/573153][1]) for a workaround [1]: https://stackoverflow.com/a/9705175/573153

以上就是Morphia: Search for null values in a list of embedded objects的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏