Counter decrement wraps around 0


#1

Hi,

As per http://developer.couchbase.com/documentation/server/4.1/developer-guide/counters.html, a counter cannot go below 0.
Thus, in cases when I’m trying to decrement from a zero value, I should get 0.
However, doing .Counter(“my key”, -1, 0, 0) from a zero value, gives me 18446744073709552000.

P.S.
One observation: I was not creating counter separately, but was using counter with an initial param “0”, thinking it should create a counter for me if not found, similar to how upsert behaves. So, If I’m using Counter (“key”, 1, 0, 0) with a non-existent key, I get the same huge humber. If I create a counter-document before with a 0 value, everything works OK.

P.P.S.
I’m on CB 4.5 DP
Go 1.6


#2

Sounds like an issue to me. @brett19 do you agree?


#3

Hey @dennis,
This indeed appears to be an issue, you can track it here: https://issues.couchbase.com/browse/GOCBC-103.
Cheers, Brett


#4

@brett19
Perfect, thank you!