[GODRIVER-565] Decode date field to int64 get zero value Created: 18/Sep/18  Updated: 24/Jul/20  Resolved: 24/Jul/20

Status: Closed
Project: Go Driver
Component/s: BSON
Affects Version/s: 0.0.13
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Mark Leung Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on GODRIVER-577 Add struct tags to choose BSON types Backlog

 Description   

DocumentResult shows correctly when passing to a bson.NewDocument.

bson.Document\{bson.Element{[objectID]"_id": ObjectID("5b989bbe733326cf1622e06a")}, bson.Element\{[UTC datetime]"datetime": 1536727804734}}

But get zero-value after marshaling struct.

type syncDateTime struct {
	ID             objectid.ObjectID `json:"id" bson:"_id, omitempty"`
	LastUpdateTime int64             `json:"datetime" bson:"datetime"`
}
 
filter := bson.NewDocument(bson.EC.String("type_key", "lastUpdateTime"))
projection := findopt.Projection(bson.NewDocument(bson.EC.Int32("datetime", 1)))
sort := findopt.Sort(bson.NewDocument(bson.EC.Int32("datetime", -1)))
result := syncDateTime{}
err := cConfig.FindOne(context.Background(), filter, projection, sort).Decode(&result)
 
{ObjectID("5b989bbe733326cf1622e06a") 0}



 Comments   
Comment by Mark Leung [ 18/Sep/18 ]

Created a pull request to fix this by adding a containerType check on date type.
https://github.com/mongodb/mongo-go-driver/pull/92

Generated at Thu Feb 08 08:34:29 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.