How to insert BSON record using Go Driver

Hi @Harshavardhan_Kumare,

What format is this record in? The example record you gave looks like something printed out by calling collection.find() in the mongo shell, but it’s important for us to know what the exact format is.

For your second question, bsonx is a set of experimental APIs that we don’t recommend for regular use because there’s no stability guarantees. You can use the public primitive.JavaScript type (primitive package - go.mongodb.org/mongo-driver/bson/primitive - Go Packages) to insert BSON JavaScript values. For example:

doc := bson.D{
    {"jsKey", primitive.JavaScript("function() { sleep(1000); }")},
}

– Divjot

1 Like