recoba78
recoba78

Reputation: 99

can i retrieve data from another collection using MongoRepository?

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 but i'm not sure

thanks !

Upvotes: 0

Views: 176

Answers (1)

DEV
DEV

Reputation: 1726

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);

Upvotes: 1

Related Questions