Ported from mongodb to cloudantdb.