[GODRIVER-967] Document that RunCommand and RunCommandCursor require an order-preserving argument Created: 16/Apr/19 Updated: 14/Jan/20 Resolved: 14/Jan/20 |
|
| Status: | Closed |
| Project: | Go Driver |
| Component/s: | Documentation |
| Affects Version/s: | 1.0.0 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Michael Burr | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Environment: |
macOS Mojave 10.14.4 (18E226) |
||
| Description |
|
I have the following code that I use to apply JSONSchema validation each time my application is started:
"schema" is JSON of the following form that is Unmarshaled into a map[string]interface{}
This frequently succeeds but I randomly get the following error (CommandNotFound) no such command: 'validator', bad cmd: '{ validator: { $jsonSchema: { bsonType: "object" }}, validationLevel: "strict", collMod: "user", $db: "ck", $readPreference: { mode: "primaryPreferred" } }' I suspect that this is the same thing that pymongo users have encountered. And I learn that Go intentionally randomizes map[] order, so this seems plausible, but I also notice that RunCommand is used throughout the driver's testing and benchmarking code. It seems like the same issue would have come up for the project developers too. |
| Comments |
| Comment by Divjot Arora (Inactive) [ 14/Jan/20 ] |
|
Closing this ticket as this requirement was documented as part of |
| Comment by Michael Burr [ 16/Apr/19 ] |
|
Nice! I wasn't aware of (the point of) bson.D. Thanks for the prompt and helpful response. |
| Comment by David Golden [ 16/Apr/19 ] |
|
Hi. You're right that the issue is the randomization of map order. If you expand the example in the RunCommand docs, you can see that it uses a bson.D for the command, which is order preserving. The other alternative is to define a struct with the command name as the first field. I'm going to rename this ticket to be about documenting the need for order preservation for RunCommand. |