0

I'm trying to get data from a MongoDB (previously saved using JS) and I unfortunately get empty _id and wrong format of the dates (saved as epoch).

Here's the data in MongoDB:

enter image description here

Here is the model I'm using in my Go code

enter image description here

and here is what I get as result

enter image description here

I've tried uuid.UUID in the ID type but I get a struct full of zeros, and when I change their types to string or byte, I get empty values.

How to get exactly the data as it's saved on the DB?

Grokify
  • 15,092
  • 6
  • 60
  • 81
Lassaad
  • 29
  • 5

1 Answers1

1

Please check your struct tags. Replace the json tag with bson.

In Mongo you store some fields in camelCase and in Go you expect all fields to be snake case.

zemicolon
  • 152
  • 1
  • 13