Details
-
Improvement
-
Resolution: Done
-
Major - P3
-
None
-
1.0.0
-
None
-
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:
command := map[string]interface{} |
command["collMod"] = collectionName |
command["validator"] = schema |
command["validationLevel"] = "strict" |
ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second) |
defer cancel()
|
err := DB.RunCommand(ctx, command).Err()
|
"schema" is JSON of the following form that is Unmarshaled into a map[string]interface{}
{
|
"$jsonSchema" : { |
"bsonType" : "object" |
}
|
}
|
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.