Java 在Spring data mongodb中从同一POJO创建两个集合
用例:我希望有两个具有相同字段的集合。一个集合将有最近的数据(比如15天),另一个集合有旧数据(比如最近6个月)。 我希望通过一个POJO实现这一点,因为基于日期进行查询,然后将其转换为VOs会更容易 底线:我想从一个POJO创建两个集合。 请建议Java 在Spring data mongodb中从同一POJO创建两个集合,java,spring,spring-data,spring-data-mongodb,Java,Spring,Spring Data,Spring Data Mongodb,用例:我希望有两个具有相同字段的集合。一个集合将有最近的数据(比如15天),另一个集合有旧数据(比如最近6个月)。 我希望通过一个POJO实现这一点,因为基于日期进行查询,然后将其转换为VOs会更容易 底线:我想从一个POJO创建两个集合。 请建议 考虑到你有类似的POJO @Document(collection = "domain") public class Domain { @Id private long id; @Indexed(unique = true
@Document(collection = "domain")
public class Domain {
@Id
private long id;
@Indexed(unique = true)
private String name;
private Date createdDate;
//getters and setters
}
Repo
中编写QueryMethods
,从POJO中提取条件数据
public interface DomainRepository extends MongoRepository<Domain, Long> {
Domain findFirstByName(String domain);
List<Domain> findByCreatedDateBetween(Date thresholdDate1, Date thresholdDate2);
}
@Document(collection = "domain")
public class Domain {
@Id
private long id;
@Indexed(unique = true)
private String name;
private Date createdDate;
//getters and setters
}
Repo
中编写QueryMethods
,从POJO中提取条件数据
public interface DomainRepository extends MongoRepository<Domain, Long> {
Domain findFirstByName(String domain);
List<Domain> findByCreatedDateBetween(Date thresholdDate1, Date thresholdDate2);
}
您的POJO中是否有日期/时间戳字段?您的POJO中是否有日期/时间戳字段?