@ View ( name = "by_username" , map = "function(doc) { if(doc.secretKey) { emit(doc.username, doc) } }" ) public CouchDbGoogleAuthenticatorAccount findOneByUsername ( final String username ) { val view = createQuery ( "by_username" ) . key ( username ) . limit ( 1 ) ; try { return db . queryView ( view , CouchDbGoogleAuthenticatorAccount . class ) . stream ( ) . findFirst ( ) . orElse ( null ) ; } catch ( final DocumentNotFoundException ignored ) { return null ; } }
Find first account for user .