埋め込まれたエンティティのリストがあります:
@Embedded
private List<EmbeddedEntity> embedded = new ArrayList<EmbeddedEntity>();
このリストでは、特定の属性(と呼びましょうfoo
)を持ち、別の属性()を持たない埋め込みエンティティを検索しますbar
。したがって、Javaではnull以外であり、MongoDBでは存在しfoo
ない必要があります。bar
次のコードを試しました(Entity
リストを含むUUIDがあります)。
Query<Entity> query = mongoDataStore.find(Entity.class).field("uuid").equal(uuid)
.field("embedded.foo").exists()
.field("embedded.bar").doesNotExist();
foo
これは、リストが空であるか、単一のエントリがある場合(値があり、bar
まだ存在しない場合)に正しく機能します。ただし、属性に値があるとすぐbar
に、クエリは間違った結果を返します。だから私はクエリを探しています。それはすべての埋め込まれたエンティティを繰り返し処理し、欠落しているものをすべて起動しますbar
。それは可能ですか?
データ例:
// 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:。でも同じ結果が得られ.field("embedded.bar").hasThisOne(null)
ます。
PPS:更新操作にクエリを使用したいので、リスト要素を手動で繰り返すことは実際にはオプションではありません。
PPS:これはMorphiaのバグだと思います-回避策については、以下の私の回答(https://stackoverflow.com/a/9705175/573153)を参照してください