Search code examples
spring-datamongorepository

SpringData MongoRepository Count and Where clause combination


I m using MongoDb and SpringData MongoRepository.. I want to fetch count messages where receiver user = ? and message readed = ? ... In short I want to fetch users unreaded messages.My method like this..But I haven't any idea how do this..Message is my mongo document.. Thanks.

@Repository
public interface MessageRepository extends MongoRepository<Message, Long> {

    Long countByReadedWhereReceiverIs(boolean readed,String receiver);

}

Solution

  • The answer is

    int countFindByReadedAndReceiver(boolean readed, String receiver);