Quantcast
Viewing all articles
Browse latest Browse all 128

Spring Data MongoDB query problem

I use the version of Spring-Data-MongoDB is 1.2, codes flow:

Code:

@Document
public class Folder {
       
        @Id
        private String id;

        @DBRef
        private Email email;
        private String name;
        private String path;
       
      Getter and Setter Method 。。。
}

Code:

@Document
public class Email {
       
        @Id
        private String id;
        @DBRef
        private User user;
        private String address;
     
      Getter and Setter Method 。。。
}

Code:

public List<Folder> findByEmailAddress(String address) {
                Query query = new Query();
                query.addCriteria(Criteria.where("email.address").is(address));
                return mongoTemplate.find(query, Folder.class);
}

or   

@Transactional
public interface FolderRepository extends MongoRepository<Folder, String>{

        List<Folder> findByEmailAddress(String address);
}

I have look up the document, up two ways is right, but the query result is empty, the database have data, so how to solve the question? thanks!

Viewing all articles
Browse latest Browse all 128

Trending Articles