Search code examples
javaspringspring-bootspring-data-jpamongorepository

Can we use MongoRespository for findByNameAndPassword() this type of queries?


Optional<TicketUserDto> ticketuser=ticketUserDao.findByUserIdAndPassword(userId, password);

DAO:

@Repository
public interface TicketUsersDao extends MongoRepository<TicketUserDto, Serializable> {
    Optional<TicketUserDto> findByUserIdAndPassword(String userId, String password);
}

And here is the DTO definition

@Document(collection="ticket_users") 
public class TicketUserDto { 
    private String userId; 
    private String password; 

    public String getUserId() { return userId; } 
    public void setUserId(String userId) { this.userId = userId; } 

    public String getPassword() { return password; } 
    public void setPassword(String password) { this.password = password; }

    @Override public String toString() { 
        return "TicketUserDto [userId=" + userId + 
            ", password=" + password + "]"; 
    } 
}

Solution

  • finally i get that i added @field then i get the values

     @Field(value="userId")
    private String userId;
    @Field(value="password")
    private String password;