Search code examples
springspring-webfluxmongorepository

Spring Web flux Mongo query


Hi I am new to Spring web flux and facing the issue regarding Mongo reactive query.

I have following structure of my model class

public class Users implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    @Id
    private String id;
    private String firstName;
    private String middleName;
    private String lastName;
    private List<Email>emails;
}


public class Email implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    String address;
    boolean verified;
}

Now I have to query that if given email exists or not in the mong document as email filed is list of email as given above.

Can any one please me on this?

I have written the following query on repository

@Query(value = "{'emails.address' : ?0 }")
    Mono<Users> findByEmails(String address);   

Solution

  • try using

    @Query("{'users.emails.address': ?0}") 
    Mono <Users> findUserByEmailAddress(final String address)