【发布时间】:2019-11-11 19:04:56
【问题描述】:
我尝试在 Offer.ProductProperties.id IN (String1, String2...) 中查找所有 Offer
public interface OfferRepository extends ReactiveMongoRepository<Offer, String> {
@Query("{'properties.id': {'$in': ?0}}")
Flux<Offer> findByPropertiesIds(List<String> propertiesId);
不幸的是,我得到了 null... 为什么?我不知道...
但这有效:
@Query("{'properties.id': ?0 }")
Flux<Offer> findByPropertiesId(String propertiesId);
报价文件:
@Document(collection = "offers")
public class Offer {
@Id
private String id;
@NotNull
@DBRef
private ProductProperties properties;
}
@Document(collection = "product_properties")
public class ProductProperties {
@Id
private String id;
(...)
}
我也尝试过使用 ReactiveMongoTemplate,但没有成功:
List<String> propIds = products.stream()
.map(product -> product.getProperties().getId())
.collect(Collectors.toList());
Query query = new Query();
query.addCriteria(Criteria.where("properties.id").in(propIds));
return mongoTemplate.find(query, Offer.class);
【问题讨论】: