Are you using Couchbase 4.0 or Couchbase 4.1?
I know there was a known bug with prepared statements and aggregations (like count, sum, etc…) in 4.0, on the server side.
If you can’t make the server upgrade, you’ll have to refrain from using prepared statements for these kind of queries I’m afraid.