[GODRIVER-850] SingleResult.Decode() not functioning as per Documentation Created: 25/Feb/19 Updated: 11/Sep/19 Resolved: 21/Mar/19 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON, Documentation |
| Affects Version/s: | 1.0.0 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Dylan Hoefsloot | Assignee: | Isabella Siu (Inactive) |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
Windows 10 |
||
| Description |
|
//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. defer cancelContext() mongoClient, _ := mongo.Connect(mongoContext, options.Client().ApplyURI("mongodb://localhost:27017")) moviesCollection.InsertOne(mongoContext, bson.M{"_id": "Deadpool", "Path": "path/to/file"{color:#bbbbbb}}) JSONData := struct { decodeError := singleResult.Decode(&JSONData) if decodeError != nil { fmt.Println("Path: ", JSONData.Path) |
| Comments |
| Comment by Isabella Siu (Inactive) [ 05/Mar/19 ] | |||
|
Hi dylan.hoefsloot@outlook.com, If you add a bson tag to the Path variable in your JSONData struct it should correctly decode your document. That would look like this:
|