Java Spring数据-“;由于com.mongodb.BasicDocument的限制,您可以';t添加第二个';creationDate“;
使用Spring引导和Spring数据,我有一个Mongo文档:Java Spring数据-“;由于com.mongodb.BasicDocument的限制,您可以';t添加第二个';creationDate“;,java,mongodb,spring-data-jpa,Java,Mongodb,Spring Data Jpa,使用Spring引导和Spring数据,我有一个Mongo文档: @Document(collection = "dogs") public class Dog{ @Id private long dogId; private LocalDateTime creationDate; ... } 我已将此方法添加到存储库中: @Repository public interface DogRepository extends CrudRepository&l
@Document(collection = "dogs")
public class Dog{
@Id
private long dogId;
private LocalDateTime creationDate;
...
}
我已将此方法添加到存储库中:
@Repository
public interface DogRepository extends CrudRepository<Dog, Long>, PagingAndSortingRepository<Dog, Long> {
Page<Dog> findAllByCreationDateAfterAndCreationDateBefore(LocalDateTime createdAfter, LocalDateTime createdBefore, Pageable pageable);
@存储库
公共接口DogRepository扩展了Crudepository、Paging和SortingRepository{
Page FindAllByCreationDateAfter和CreationDateBefore(LocalDateTime createdAfter、LocalDateTime createdBefore、Pageable Pageable);
在运行时尝试访问该方法时,出现以下错误:
“由于com.mongodb.BasicDocument的限制,无法添加第二个指定为'creationDate:Document{{{$lt=2021-05-12T09:42:08.549}}的'creationDate'表达式。条件已包含'creationDate:Document{{$gt=2021-05-12T09:42:07.486}'。”
要解决此问题,需要更改Spring数据方法,并在之间使用
:
Page<Dog> findAllByCreationDateBetween(LocalDateTime createdAfter, LocalDateTime createdBefore, Pageable pageable);
Page findAllByCreationDateBetween(LocalDateTime createdAfter、LocalDateTime createdBefore、Pageable Pageable);
如本文所示,您可以使用: