description: bulkWrite-replaceOne-hint-unacknowledged

schemaVersion: '1.0'

createEntities:
  - client:
      id: &client0 client0
      observeEvents:
        - commandStartedEvent
  - database:
      id: &database0 database0
      client: *client0
      databaseName: &database0Name db0
  - collection:
      id: &collection0 collection0
      database: *database0
      collectionName: &collection0Name coll0
      collectionOptions:
        writeConcern: { w: 0 }

initialData:
  - collectionName: *collection0Name
    databaseName: *database0Name
    documents: &documents
      - { _id: 1, x: 11 }
      - { _id: 2, x: 22 }

tests:
  - description: "Unacknowledged replaceOne with hint string fails with client-side error on pre-4.2 server"
    runOnRequirements:
      - maxServerVersion: "4.0.99"
    operations:
      - object: *collection0
        name: bulkWrite
        arguments:
          requests:
            - replaceOne:
                filter: &filter { _id: { $gt: 1 } }
                replacement: &replacement { x: 111 }
                hint: _id_
        expectError:
          isClientError: true
    expectEvents: &noEvents
      - client: *client0
        events: []

  - description: "Unacknowledged replaceOne with hint document fails with client-side error on pre-4.2 server"
    runOnRequirements:
      - maxServerVersion: "4.0.99"
    operations:
      - object: *collection0
        name: bulkWrite
        arguments:
          requests:
            - replaceOne:
                filter: *filter
                replacement: *replacement
                hint: { _id: 1 }
        expectError:
          isClientError: true
    expectEvents: *noEvents

  - description: "Unacknowledged replaceOne with hint string on 4.2+ server"
    runOnRequirements:
      - minServerVersion: "4.2.0"
    operations:
      - object: *collection0
        name: bulkWrite
        arguments:
          requests:
            - replaceOne:
                filter: *filter
                replacement: *replacement
                hint: _id_
        expectResult: &unacknowledgedResult { $$unsetOrMatches: { acknowledged: { $$unsetOrMatches: false } } }
    expectEvents: &events
      - client: *client0
        events:
          - commandStartedEvent:
              command:
                update: *collection0Name
                updates:
                  - q: *filter
                    u: *replacement
                    multi: { $$unsetOrMatches: false }
                    upsert: { $$unsetOrMatches: false }
                    hint: { $$type: [ string, object ]}
                writeConcern: { w: 0 }

  - description: "Unacknowledged replaceOne with hint document on 4.2+ server"
    runOnRequirements:
      - minServerVersion: "4.2.0"
    operations:
      - object: *collection0
        name: bulkWrite
        arguments:
          requests:
            - replaceOne:
                filter: *filter
                replacement: *replacement
                hint: { _id: 1 }
        expectResult: *unacknowledgedResult
    expectEvents: *events
