@ View ( name = "count_by_userId" , map = "function(doc) { if(doc.token && doc.userId) { emit(doc.userId, doc) } }" , reduce = "_count" ) public long countByUserId ( final String userId ) { val view = createQuery ( "count_by_userId" ) . key ( userId ) ; val rows = db . queryView ( view ) . getRows ( ) ; if ( rows . isEmpty ( ) ) { return 0 ; } return rows . get ( 0 ) . getValueAsInt ( ) ; }
Token count for a user .