Select function for couchdb