Inserting data in timeseries collection throws error when using go driver

Go mongo driver throws error stating:

write exception: write errors: [‘timestamp’ must be present and contain a valid BSON UTC datetime value]

Tried values for timestamp field in code are as follows:

dataForDB[“timestamp”] = map[string]interface{}{"$timestamp": primitive.Timestamp{T: uint32(time.Now().Unix())}}


dataForDB[“timestamp”] = primitive.Timestamp{T: uint32(time.Now().Unix())}

Both of these fail with the same error as stated above.
Any help is appreciated.

Thanks :slight_smile:

doc := bson.D{{"timestamp",primitive.NewDateTimeFromTime(time.Now().UTC())}}

With this code i was able to insert the document into a time-series collection