globalsign / mgo

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

BSON unmarshal unable to parse $date #404

Open Tang8330 opened 1 year ago

Tang8330 commented 1 year 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)?

db version v6.0.1
Build Info: {
    "version": "6.0.1",
    "gitVersion": "32f0f9c88dc44a2c8073a5bd47cf779d4bfdee6b",
    "modules": [],
    "allocator": "system",
    "environment": {
        "distarch": "aarch64",
        "target_arch": "aarch64"
    }
}

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

go1.19

What did you do?

If possible, provide a recipe for reproducing the error. A runnable program is great and really helps!

var tsMap map[string]interface{}
    bsonData := []byte(`
{"_id": {"$numberLong": "10004"},"order_date": {"$date": 1456012800000},"purchaser_id": {"$numberLong": "1003"},"quantity": 1,"product_id": {"$numberLong": "107"}}

`)
err := bson.UnmarshalJSON(bsonData, &tsMap)

assert.NoError(p.T(), err)

Instead of it working, it returned an error, see: err cannot parse date: "{\"$date\": 1456012800000}"

Can you reproduce the issue on the latest development branch?