次の問題があります-ネストされたプロパティでクエリを実行する方法は@Query
?
My Product クラス (Mongo のドキュメント):
@Document(collection = "products")
public class Product {
@Id
private String id;
@DBRef
private ProductProperties properties;
Mongo ではどのように表示されますか:
{
"_id" : ObjectId("5d5e78d20e8e3d0006079a84"),
"companyId" : "1234",
"properties" : {
"$ref" : "properties",
"$id" : ObjectId("5df8dd2331ea7b4a9384335b")
},
"calendar" : [
{
"startDate" : ISODate("2019-09-04T22:00:00.000Z"),
"endDate" : ISODate("2019-09-09T22:00:00.000Z")
}
],
"_class" : "org.abc.def"
}
ProductProperties クラス (Mongo のドキュメント):
@Document(collection = "product_properties")
public class ProductProperties {
@Id
private String id;
(...)
Mongo ではどのように表示されますか:
{
"_id" : ObjectId("5df8dd2331ea7b4a9384335b"),
"brand" : "offer Brand_1",
"model" : "offer model_1",
"modelNumber" : "offer model number_1",
"size" : {
...
}
私の春のリポジトリ:
public interface ProductRepository extends MongoRepository<Product, String> {
@Query("{'properties.id': ?0 }")
List<Product> findByPropertiesId(String propertiesId);
私も試しました:
List<Product> findByProperties_id(String propertiesId)
また
@Query("{'properties.$id': ?0 }")
List<Product> findByPropertiesId(ObjectId propertiesId);
しかし、成功せずに。何が悪いかわかりますか?
私が呼び出すとき:
public List<Product> findProductsByPropertiesId(String properties) {
if (properties == null) {
throw new IllegalArgumentException("onFind: propertiesId should not be null.");
}
return productRepository.findByProperties_Id(properties);
}
私は空のリストを取得します:(
たぶんクエリ経由でそれを行うことは不可能ですか?