Use couch buit-in functions.
Merge pull request #4289 from HassenRiahi/ImproveReduceDBSPub

Use couch buit-in functions.