last day (22 days later) » 

7:08 PM
2
Q: Golang: MongoDB Double Type cannot decode into Float64

KiranCurrently running into an issue where the mongodb double type cannot decode into a float64 and its saying that its a string This is the error: 2022/08/02 14:24:02 error decoding key imdb.rating: cannot decode string into a float32 or float64 type and this is what the imdb struct looks like: ...

 
You must not leave a space before the option: bson:"rating,truncate"
 
mmm ok thanks! I fixed that but still no good
 
Are you sure it"s double in DB and not a string? Please post an example document, and the Go code that performs the query.
 
Just updated with document and calling code
 
Your example works for me with or without the ,truncate option. What do you get if you enter typeof db.movies.findOne().imdb.rating in the mongo shell?
Also what version of the driver do you use? Please try to update to the latest version and try with that too. And what version of MongoDB do you have?
Also what do you get if you run db.movies.aggregate({$project:{rating_type:{$type:"$imdb.rat‌​ing"}}}) in the mongo shell?
 
7:08 PM
let me try those real quick and see what I get.
aggregate function: <br/> `[
  { _id: ObjectId("573a1391f29313caabcd7e23"), rating_type: 'double' },
  { _id: ObjectId("573a1390f29313caabcd587d"), rating_type: 'double' },
  { _id: ObjectId("573a1391f29313caabcd70b4"), rating_type: 'double' },
  { _id: ObjectId("573a1391f29313caabcd6d90"), rating_type: 'double' },
  { _id: ObjectId("573a1391f29313caabcd6e2a"), rating_type: 'double' },
  { _id: ObjectId("573a1391f29313caabcd715c"), rating_type: 'double' }
]
`<br/> the "typeof" came back with "number"
im using Mongo Atlas so its 5.0.10
 
 
2 hours later…
9:03 PM
and whats your driver version?
if you don't know, check your go.mod file, it has a require section, search for go.mongodb.org/mongo-driver
or run the following command in your module's folder:
go list -m go.mongodb.org/mongo-driver
 

  last day (22 days later) »