【发布时间】:2021-12-30 02:20:57
【问题描述】:
我正在使用 spring-data-mongodb 将我的 Java 对象保存到 MongoDB。除一项特定操作外,一切正常:
@Override
public Collection<MyDocument> findAllByTags(Collection<String> tags) {
FindIterable<MyDocument> results = operations.getCollection(COLLECTION_NAME)
.find(Filters.all(FIELD_TAGS, tags), MyDocument.class);
return StreamSupport.stream(results.spliterator(), false).collect(Collectors.toList());
}
文档类如下所示:
@Getter
@Setter
@NoArgsConstructor
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
@Document
public class MyDocument implements MyEntity {
@Id
@EqualsAndHashCode.Include
@BsonProperty("myId")
private String myId;
@BsonProperty("dateCreated")
private Date dateCreated;
@BsonProperty("otherField")
private String otherField;
@Indexed
@BsonProperty("tags")
private Collection<String> tags;
//more fields
所有对象的所有字段都按预期返回,但带有@Id 注释的字段设置为null。有谁知道是什么导致了这种行为以及如何解决它?感谢您的宝贵时间。
【问题讨论】: