data:
  - { _id: 1, x: 11 }
  - { _id: 2, x: 22 }
  - { _id: 3, x: 33 }
  - { _id: 4, x: 44 }
  - { _id: 5, x: 55 }

collection_name: &collection_name "test"
database_name: &database_name "command-monitoring-tests"
namespace: &namespace "command-monitoring-tests.test"

tests:
  -
    description: "A successful find event with no options"
    operation:
      name: "find"
      arguments:
        filter: { _id: 1 }
    expectations:
      -
        command_started_event:
          command:
            find: *collection_name
            filter: { _id: 1 }
          command_name: "find"
          database_name: *database_name
      -
        command_succeeded_event:
          reply:
            ok: 1.0
            cursor:
              id: { $numberLong: "0" }
              ns: *namespace
              firstBatch:
                - { _id: 1, x: 11 }
          command_name: "find"
  -
    description: "A successful find event with options"
    operation:
      name: "find"
      read_preference: { mode: "primaryPreferred" }
      arguments:
        filter: { _id: { $gt: 1 } }
        sort: { _id: 1 }
        skip: {"$numberLong": "2"}
        modifiers:
          $comment: "test"
          $hint: { _id: 1 }
          $max: { _id: 6 }
          $maxTimeMS: 6000
          $min: { _id: 0 }
          $returnKey: false
          $showDiskLoc: false
    expectations:
      -
        command_started_event:
          command:
            find: *collection_name
            filter: { _id:  { $gt: 1 } }
            sort: { _id: 1 }
            skip: {"$numberLong": "2"}
            comment: "test"
            hint: { _id: 1 }
            max: { _id: 6 }
            maxTimeMS: 6000
            min: { _id: 0 }
            returnKey: false
            showRecordId: false
          command_name: "find"
          database_name: *database_name
      -
        command_succeeded_event:
          reply:
            ok: 1.0
            cursor:
              id: { $numberLong: "0" }
              ns: *namespace
              firstBatch:
                - { _id: 4, x: 44 }
                - { _id: 5, x: 55 }
          command_name: "find"
  -
    description: "A successful find event with a getmore"
    operation:
      name: "find"
      arguments:
        filter: { _id: { $gte: 1 }}
        sort: { _id: 1 }
        batchSize: {"$numberLong": "3"}
    expectations:
      -
        command_started_event:
          command:
            find: *collection_name
            filter: { _id: { $gte : 1 }}
            sort: { _id: 1 }
            batchSize: {"$numberLong": "3"}
          command_name: "find"
          database_name: *database_name
      -
        command_succeeded_event:
          reply:
            ok: 1.0
            cursor:
              id: { $numberLong: "42" }
              ns: *namespace
              firstBatch:
                - { _id: 1, x: 11 }
                - { _id: 2, x: 22 }
                - { _id: 3, x: 33 }
          command_name: "find"
      -
        command_started_event:
          command:
            getMore: { $numberLong: "42" }
            collection: *collection_name
            batchSize: {"$numberLong": "3"}
          command_name: "getMore"
          database_name: *database_name
      -
        command_succeeded_event:
          reply:
            ok: 1.0
            cursor:
              id: { $numberLong: "0" }
              ns: *namespace
              nextBatch:
                - { _id: 4, x: 44 }
                - { _id: 5, x: 55 }
          command_name: "getMore"
  -
    description: "A successful find event with a getmore and killcursors"
    ignore_if_server_version_greater_than: "3.0"
    operation:
      name: "find"
      arguments:
        filter: { _id: { $gte: 1 }}
        sort: { _id: 1 }
        batchSize: {"$numberLong": "3"}
        limit: {"$numberLong": "4"}
    expectations:
      -
        command_started_event:
          command:
            find: *collection_name
            filter: { _id: { $gte : 1 }}
            sort: { _id: 1 }
            batchSize: {"$numberLong": "3"}
            limit: {"$numberLong": "4"}
          command_name: "find"
          database_name: *database_name
      -
        command_succeeded_event:
          reply:
            ok: 1.0
            cursor:
              id: { $numberLong: "42" }
              ns: *namespace
              firstBatch:
                - { _id: 1, x: 11 }
                - { _id: 2, x: 22 }
                - { _id: 3, x: 33 }
          command_name: "find"
      -
        command_started_event:
          command:
            getMore: { $numberLong: "42" }
            collection: *collection_name
            batchSize: { $numberLong: "1" }
          command_name: "getMore"
          database_name: *database_name
      -
        command_succeeded_event:
          reply:
            ok: 1.0
            cursor:
              id: { $numberLong: "42" }
              ns: *namespace
              nextBatch:
                - { _id: 4, x: 44 }
          command_name: "getMore"
      -
        command_started_event:
          command:
            killCursors: *collection_name
            cursors:
              - { $numberLong: "42" }
          command_name: "killCursors"
          database_name: *database_name
      -
        command_succeeded_event:
          reply:
            ok: 1.0
            cursorsUnknown:
              - { $numberLong: "42" }
          command_name: "killCursors"
  -
    description: "A successful find event with a getmore and the server kills the cursor"
    ignore_if_server_version_less_than: "3.1"
    ignore_if_topology_type:
      - "sharded"
    operation:
      name: "find"
      arguments:
        filter: { _id: { $gte: 1 }}
        sort: { _id: 1 }
        batchSize: {"$numberLong": "3"}
        limit: {"$numberLong": "4"}
    expectations:
      -
        command_started_event:
          command:
            find: *collection_name
            filter: { _id: { $gte : 1 }}
            sort: { _id: 1 }
            batchSize: {"$numberLong": "3"}
            limit: {"$numberLong": "4"}
          command_name: "find"
          database_name: *database_name
      -
        command_succeeded_event:
          reply:
            ok: 1.0
            cursor:
              id: { $numberLong: "42" }
              ns: *namespace
              firstBatch:
                - { _id: 1, x: 11 }
                - { _id: 2, x: 22 }
                - { _id: 3, x: 33 }
          command_name: "find"
      -
        command_started_event:
          command:
            getMore: { $numberLong: "42" }
            collection: *collection_name
            batchSize: { $numberLong: "1" }
          command_name: "getMore"
          database_name: *database_name
      -
        command_succeeded_event:
          reply:
            ok: 1.0
            cursor:
              id: { $numberLong: "0" }
              ns: *namespace
              nextBatch:
                - { _id: 4, x: 44 }
          command_name: "getMore"
  -
    description: "A failed find event"
    operation:
      name: "find"
      arguments:
        filter: { $or: true }
    expectations:
      -
        command_started_event:
          command:
            find: *collection_name
            filter: { $or: true }
          command_name: "find"
          database_name: *database_name
      -
        command_failed_event:
          command_name: "find"
