Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-967

Document that RunCommand and RunCommandCursor require an order-preserving argument

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.0.0
    • Component/s: Documentation
    • None
    • Environment:
      macOS Mojave 10.14.4 (18E226)

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            mburr Michael Burr
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: