Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2659

bson.UnmarshalExtJSONWithContext does not work for $date

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      Summary

      As per title. I'm unable to unmarshal a BSON document.

      Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

      How to Reproduce

      func (p *MongoTestSuite) TestBsonTypes() {
         var tsMap map[string]interface{}
         dc := bsoncodec.DecodeContext{Registry: bson.DefaultRegistry}
         err := bson.UnmarshalExtJSONWithContext(dc, []byte(`
      {"_id": {"$numberLong": "10004"},"order_date": {"$date": 1456012800000},"purchaser_id": {"$numberLong": "1003"},"quantity": 1,"product_id": {"$numberLong": "107"}}
      
      `), true, &tsMap)
         assert.NoError(p.T(), err)
         fmt.Println("tsMap", tsMap, "err", err)
         assert.True(p.T(), false)
      }

       
      This test will fail, and value of tsMap and the error that is returned is:

      tsMap map[_id:10004] 
      
      err error decoding key order_date: invalid JSON input; expected {

       

      Additional Background

      It's clearly able to unmarshal and fetch $numberLong, but $date is not working.

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            rtang.cs@gmail.com Robin Tang
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: