globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

time.Duration values not made back into milliseconds on unmarshall #304

Closed KidLinus closed 5 years ago

KidLinus commented 5 years ago

We use the issue tracker to track bugs with mgo - if you have a usage question, it's best to try Stack Overflow :)

Replace this text with your description, and please answer the questions below before submitting your issue to help us out. Thanks!


What version of MongoDB are you using (mongod --version)?

3.4.14

What version of Go are you using (go version)?

go1.10.2 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/linus/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/linus/go"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/1c/6y3ksqzd1r5bd6gd9_r_0yv00000gn/T/go-build530340622=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I have a few models that store durations in time.Duration. When marshalling these they get divided by 1000 which i understand is expected behaviour. However when i then load the same document back from Mongo the time.Duration does not get multiplied back to Go format. This is a very weird behaviour, I've had to write custom Unmarshal functions that multiply values by 1000.

Can you reproduce the issue on the latest development branch?

Not sure yet.

KidLinus commented 5 years ago

I found my issue. The bson tag was incorrect on my struct and coincidently the logger also truncated the number so it was a false positive. You may close this.