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

Document that RunCommand and RunCommandCursor require an order-preserving argument

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 1.0.0
    • Documentation
    • 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.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: