英文:
can i retrieve data from another collection using MongoRepository?
问题
我有一个名为"Invoice"的类和一个MongoRepository,我想从我的Mongo数据库中提取所有已验证的发票(在给定时间范围内创建的发票)。以下是我的Mongo存储库代码:
import java.util.Date;
import java.util.List;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import Invoices.Invoice;
@Repository
public interface InvoiceRepositoryMongo extends MongoRepository<Invoice, Integer> {
@Query("db.invoices_bis.find({createdAt : {$gte : new ISODate('2013-04-30T17:24:16.000+00:00') , $lte : new ISODate('2013-05-30T17:24:16.000+00:00')}})")
List<Document> testrequete(Date start, Date ed);
}
不要太关注查询,它只是用于测试的。但问题是,当我运行这个代码时,我遇到了这个错误:
"nested exception is org.springframework.data.mapping.PropertyReferenceException: No property testrequete found for type Invoice!"
我认为问题在于该方法返回了一个<Document>列表,但我不确定。谢谢!
英文:
i have a class called "Invoice" and a MongoRepository
and what i want is to extract from my mongo database all validated invoices (those created in a given time range)
so here is my mongo repository :
import java.util.Date;
import java.util.List;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;
import Invoices.Invoice;
@Repository
public interface InvoiceRepositoryMongo extends MongoRepository<Invoice,Integer>{
@Query("db.invoices_bis.find({createdAt : {$gte : new ISODate('2013-04-30T17:24:16.000+00:00') , $lte : new ISODate('2013-05-30T17:24:16.000+00:00')}})")
List<Document> testrequete(Date start, Date ed);
}
dont pay too much attention to the query it is just for testing , but the problem is when i run this , i have this error :
nested exception is org.springframework.data.mapping.PropertyReferenceException: No property testrequete found for type Invoice!
i think the problem is that the method return a list of <Document> but i'm not sure
thanks !
答案1
得分: 1
我认为问题出在你的实体称为 Invoice 的部分,
MongoRepository<Invoice, Integer>
所以结果应该类似于:
List<Invoice> testrequete(Date start, Date ed);
英文:
i think te problem is that your Entity calls Invoice,
MongoRepository<Invoice,Integer>
so the result should be something like :
List<Invoice> testrequete(Date start, Date ed);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论