{
  "description": "aggregate",
  "schemaVersion": "1.0",
  "createEntities": [
    {
      "client": {
        "id": "client0",
        "useMultipleMongoses": true,
        "observeEvents": [
          "commandStartedEvent"
        ]
      }
    },
    {
      "database": {
        "id": "database0",
        "client": "client0",
        "databaseName": "aggregate-tests"
      }
    },
    {
      "collection": {
        "id": "collection0",
        "database": "database0",
        "collectionName": "coll0"
      }
    }
  ],
  "initialData": [
    {
      "collectionName": "coll0",
      "databaseName": "aggregate-tests",
      "documents": [
        {
          "_id": 1,
          "x": 11
        },
        {
          "_id": 2,
          "x": 22
        },
        {
          "_id": 3,
          "x": 33
        },
        {
          "_id": 4,
          "x": 44
        },
        {
          "_id": 5,
          "x": 55
        },
        {
          "_id": 6,
          "x": 66
        }
      ]
    }
  ],
  "tests": [
    {
      "description": "aggregate with multiple batches works",
      "operations": [
        {
          "name": "aggregate",
          "arguments": {
            "pipeline": [
              {
                "$match": {
                  "_id": {
                    "$gt": 1
                  }
                }
              }
            ],
            "batchSize": 2
          },
          "object": "collection0",
          "expectResult": [
            {
              "_id": 2,
              "x": 22
            },
            {
              "_id": 3,
              "x": 33
            },
            {
              "_id": 4,
              "x": 44
            },
            {
              "_id": 5,
              "x": 55
            },
            {
              "_id": 6,
              "x": 66
            }
          ]
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "aggregate": "coll0",
                  "pipeline": [
                    {
                      "$match": {
                        "_id": {
                          "$gt": 1
                        }
                      }
                    }
                  ],
                  "cursor": {
                    "batchSize": 2
                  }
                },
                "commandName": "aggregate",
                "databaseName": "aggregate-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "getMore": {
                    "$$type": [
                      "int",
                      "long"
                    ]
                  },
                  "collection": "coll0",
                  "batchSize": 2
                },
                "commandName": "getMore",
                "databaseName": "aggregate-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "getMore": {
                    "$$type": [
                      "int",
                      "long"
                    ]
                  },
                  "collection": "coll0",
                  "batchSize": 2
                },
                "commandName": "getMore",
                "databaseName": "aggregate-tests"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "aggregate with a string comment",
      "runOnRequirements": [
        {
          "minServerVersion": "3.6.0"
        }
      ],
      "operations": [
        {
          "name": "aggregate",
          "arguments": {
            "pipeline": [
              {
                "$match": {
                  "_id": {
                    "$gt": 1
                  }
                }
              }
            ],
            "comment": "comment"
          },
          "object": "collection0"
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "aggregate": "coll0",
                  "pipeline": [
                    {
                      "$match": {
                        "_id": {
                          "$gt": 1
                        }
                      }
                    }
                  ],
                  "comment": "comment"
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "aggregate with a document comment",
      "runOnRequirements": [
        {
          "minServerVersion": "4.4"
        }
      ],
      "operations": [
        {
          "name": "aggregate",
          "arguments": {
            "pipeline": [
              {
                "$match": {
                  "_id": {
                    "$gt": 1
                  }
                }
              }
            ],
            "comment": {
              "content": "test"
            }
          },
          "object": "collection0"
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "aggregate": "coll0",
                  "pipeline": [
                    {
                      "$match": {
                        "_id": {
                          "$gt": 1
                        }
                      }
                    }
                  ],
                  "comment": {
                    "content": "test"
                  }
                }
              }
            }
          ]
        }
      ]
    },
    {
      "description": "aggregate with a document comment - pre 4.4",
      "runOnRequirements": [
        {
          "minServerVersion": "3.6.0",
          "maxServerVersion": "4.2.99"
        }
      ],
      "operations": [
        {
          "name": "aggregate",
          "object": "collection0",
          "arguments": {
            "pipeline": [
              {
                "$match": {
                  "_id": {
                    "$gt": 1
                  }
                }
              }
            ],
            "comment": {
              "content": "test"
            }
          },
          "expectError": {
            "isClientError": false
          }
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "aggregate": "coll0",
                  "pipeline": [
                    {
                      "$match": {
                        "_id": {
                          "$gt": 1
                        }
                      }
                    }
                  ],
                  "comment": {
                    "content": "test"
                  }
                },
                "commandName": "aggregate",
                "databaseName": "aggregate-tests"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "aggregate with comment sets comment on getMore",
      "runOnRequirements": [
        {
          "minServerVersion": "4.4.0"
        }
      ],
      "operations": [
        {
          "name": "aggregate",
          "arguments": {
            "pipeline": [
              {
                "$match": {
                  "_id": {
                    "$gt": 1
                  }
                }
              }
            ],
            "batchSize": 2,
            "comment": {
              "content": "test"
            }
          },
          "object": "collection0",
          "expectResult": [
            {
              "_id": 2,
              "x": 22
            },
            {
              "_id": 3,
              "x": 33
            },
            {
              "_id": 4,
              "x": 44
            },
            {
              "_id": 5,
              "x": 55
            },
            {
              "_id": 6,
              "x": 66
            }
          ]
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "aggregate": "coll0",
                  "pipeline": [
                    {
                      "$match": {
                        "_id": {
                          "$gt": 1
                        }
                      }
                    }
                  ],
                  "cursor": {
                    "batchSize": 2
                  },
                  "comment": {
                    "content": "test"
                  }
                },
                "commandName": "aggregate",
                "databaseName": "aggregate-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "getMore": {
                    "$$type": [
                      "int",
                      "long"
                    ]
                  },
                  "collection": "coll0",
                  "batchSize": 2,
                  "comment": {
                    "content": "test"
                  }
                },
                "commandName": "getMore",
                "databaseName": "aggregate-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "getMore": {
                    "$$type": [
                      "int",
                      "long"
                    ]
                  },
                  "collection": "coll0",
                  "batchSize": 2,
                  "comment": {
                    "content": "test"
                  }
                },
                "commandName": "getMore",
                "databaseName": "aggregate-tests"
              }
            }
          ]
        }
      ]
    },
    {
      "description": "aggregate with comment does not set comment on getMore - pre 4.4",
      "runOnRequirements": [
        {
          "minServerVersion": "3.6.0",
          "maxServerVersion": "4.3.99"
        }
      ],
      "operations": [
        {
          "name": "aggregate",
          "arguments": {
            "pipeline": [
              {
                "$match": {
                  "_id": {
                    "$gt": 1
                  }
                }
              }
            ],
            "batchSize": 2,
            "comment": "comment"
          },
          "object": "collection0",
          "expectResult": [
            {
              "_id": 2,
              "x": 22
            },
            {
              "_id": 3,
              "x": 33
            },
            {
              "_id": 4,
              "x": 44
            },
            {
              "_id": 5,
              "x": 55
            },
            {
              "_id": 6,
              "x": 66
            }
          ]
        }
      ],
      "expectEvents": [
        {
          "client": "client0",
          "events": [
            {
              "commandStartedEvent": {
                "command": {
                  "aggregate": "coll0",
                  "pipeline": [
                    {
                      "$match": {
                        "_id": {
                          "$gt": 1
                        }
                      }
                    }
                  ],
                  "cursor": {
                    "batchSize": 2
                  },
                  "comment": "comment"
                },
                "commandName": "aggregate",
                "databaseName": "aggregate-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "getMore": {
                    "$$type": [
                      "int",
                      "long"
                    ]
                  },
                  "collection": "coll0",
                  "batchSize": 2,
                  "comment": {
                    "$$exists": false
                  }
                },
                "commandName": "getMore",
                "databaseName": "aggregate-tests"
              }
            },
            {
              "commandStartedEvent": {
                "command": {
                  "getMore": {
                    "$$type": [
                      "int",
                      "long"
                    ]
                  },
                  "collection": "coll0",
                  "batchSize": 2,
                  "comment": {
                    "$$exists": false
                  }
                },
                "commandName": "getMore",
                "databaseName": "aggregate-tests"
              }
            }
          ]
        }
      ]
    }
  ]
}
