-
Type:
Task
-
Resolution: Done
-
Priority:
Minor - P4
-
None
-
Affects Version/s: 1.0.0
-
Component/s: BSON, Documentation
-
None
-
Environment:Windows 10
-
None
-
None
-
None
-
None
-
None
-
None
-
None
//This is the code I have used, it produces no errors however, JSONData.Path is an empty string on completion. This is how to documentation says to do it.
mongoContext, cancelContext := context.WithTimeout(context.Background(), 10*time.Second)
defer cancelContext()
mongoClient, _ := mongo.Connect(mongoContext, options.Client().ApplyURI("mongodb://localhost:27017"))
moviesCollection := mongoClient.Database("Entertainment").Collection("Movies")
moviesCollection.InsertOne(mongoContext, bson.M{"_id": "Deadpool", "Path": "path/to/file"{color:#bbbbbb}})
singleResult := moviesCollection.FindOne(context.Background(), bson.M{"_id": "Deadpool"{color:#bbbbbb}})
if singleResult.Err() != nil {
log.Println("Find error: ", singleResult.Err())
}
JSONData := struct {
Path string `json:"Path"`
}{}
decodeError := singleResult.Decode(&JSONData)
if decodeError != nil {
log.Println("Decode error: ", decodeError)
}
fmt.Println("Path: ", JSONData.Path)