{
  "description": "updateMany-let",
  "schemaVersion": "1.0",
  "createEntities": [
    {
      "client": {
        "id": "client0",
        "observeEvents": [
          "commandStartedEvent"
        ]
      }
    },
    {
      "database": {
        "id": "database0",
        "client": "client0",
        "databaseName": "crud-tests"
      }
    },
    {
      "collection": {
        "id": "collection0",
        "database": "database0",
        "collectionName": "coll0"
      }
    }
  ],
  "initialData": [
    {
      "collectionName": "coll0",
      "databaseName": "crud-tests",
      "documents": [
        {
          "_id": 1
        },
        {
          "_id": 2,
          "name": "name"
        },
        {
          "_id": 3,
          "name": "name"
        }
      ]
    }
  ],
  "tests": [
    {
      "description": "updateMany with let option",
      "runOnRequirements": [
        {
          "minServerVersion": "5.0"
        }
      ],
      "operations": [
        {
          "name": "updateMany",
          "object": "collection0",
          "arguments": {
            "filter": {
              "$expr": {
                "$eq": [
                  "$name",
                  "$$name"
                ]
              }
            },
            "update": [
              {
                "$set": {
                  "x": "$$x",
                  "y": "$$y"
                }
              }
            ],
            "let": {
              "name": "name",
              "x": "foo",
              "y": {
                "$literal": "bar"
              }
            }
          },
          "expectResult": {
            "matchedCount": 2,
            "modifiedCount": 2,
            "upsertedCount": 0
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "update": "coll0",
                  "updates": [
                    {
                      "q": {
                        "$expr": {
                          "$eq": [
                            "$name",
                            "$$name"
                          ]
                        }
                      },
                      "u": [
                        {
                          "$set": {
                            "x": "$$x",
                            "y": "$$y"
                          }
                        }
                      ],
                      "multi": true,
                      "upsert": {
                        "$$unsetOrMatches": false
                      }
                    }
                  ],
                  "let": {
                    "name": "name",
                    "x": "foo",
                    "y": {
                      "$literal": "bar"
                    }
                  }
                }
              }
            }
          ]
        }
      ],
      "outcome": [
        {
          "collectionName": "coll0",
          "databaseName": "crud-tests",
          "documents": [
            {
              "_id": 1
            },
            {
              "_id": 2,
              "name": "name",
              "x": "foo",
              "y": "bar"
            },
            {
              "_id": 3,
              "name": "name",
              "x": "foo",
              "y": "bar"
            }
          ]
        }
      ]
    },
    {
      "description": "updateMany with let option unsupported (server-side error)",
      "runOnRequirements": [
        {
          "minServerVersion": "4.2.0",
          "maxServerVersion": "4.4.99"
        }
      ],
      "operations": [
        {
          "name": "updateMany",
          "object": "collection0",
          "arguments": {
            "filter": {
              "_id": 1
            },
            "update": [
              {
                "$set": {
                  "x": "$$x"
                }
              }
            ],
            "let": {
              "x": "foo"
            }
          },
          "expectError": {
            "errorContains": "'update.let' is an unknown field",
            "isClientError": false
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "update": "coll0",
                  "updates": [
                    {
                      "q": {
                        "_id": 1
                      },
                      "u": [
                        {
                          "$set": {
                            "x": "$$x"
                          }
                        }
                      ],
                      "multi": true,
                      "upsert": {
                        "$$unsetOrMatches": false
                      }
                    }
                  ],
                  "let": {
                    "x": "foo"
                  }
                }
              }
            }
          ]
        }
      ],
      "outcome": [
        {
          "collectionName": "coll0",
          "databaseName": "crud-tests",
          "documents": [
            {
              "_id": 1
            },
            {
              "_id": 2,
              "name": "name"
            },
            {
              "_id": 3,
              "name": "name"
            }
          ]
        }
      ]
    }
  ]
}
