support count and delete_by_query

 - support count of results based on queries
 - support delete_based on queries
 - refactor tests for these