[GODRIVER-1608] Reordered fields in bson.M document Created: 07/May/20 Updated: 27/Oct/23 Resolved: 09/May/20 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | BSON |
| Affects Version/s: | 1.3.3 |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Old Old | Assignee: | Unassigned |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
ubuntu 18.04 |
||
| Description |
|
Hi, I've noticed a weird behavior when decoding result to bson.M for some reason, all the field of the bson.M document are sorted when fetched from a collection. Not sure if the reordering happens during Find or Decode though go code to reproduce the issue:
output:
expected behavior (mongo shell): the field order should not change
the old mgo driver was not changing the field order This was initially noticed here: mongoplayground.net/p/6--axoMYpDZ |
| Comments |
| Comment by Divjot Arora (Inactive) [ 09/May/20 ] |
|
No worries, thanks for confirming. I'm going to close this ticket as "works as designed" but feel free to leave a comment or open a new ticket if you have further questions. |
| Comment by Old Old [ 08/May/20 ] |
|
Hi @Divjot Arora, Thank you for the quick answer. You're totally right, this is unrelated to the mongo-go-driver, I forgot that go map doesn't keep insertion order Sorry for bothering you |
| Comment by Divjot Arora (Inactive) [ 08/May/20 ] |
|
Thank you for the detailed report. There's a couple of things going on here and I don't think this is a driver bug:
You can see that both mgo and the driver can't preserve the same key order as the original BSON document when using a tool that doesn't print out keys in sorted order by default like go-spew: https://gist.github.com/divjotarora/43bdb0bbb54f0268f72342da5e18b6e6. |