ROOTPLOIT
Server: LiteSpeed
System: Linux in-mum-web1878.main-hosting.eu 5.14.0-570.21.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 11 07:22:35 EDT 2025 x86_64
User: u435929562 (435929562)
PHP: 7.4.33
Disabled: system, exec, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/go/pkg/mod/go.mongodb.org/[email protected]/testdata/transactions/legacy/read-pref.yml
# This test doesn't check contents of command-started events.
runOn:
    -
        minServerVersion: "4.0"
        topology: ["replicaset"]
    -
        minServerVersion: "4.1.8"
        topology: ["sharded"]

database_name: &database_name "transaction-tests"
collection_name: &collection_name "test"

data: []

tests:
  - description: default readPreference

    operations:
      - name: startTransaction
        object: session0
      - name: insertMany
        object: collection
        arguments:
          documents: &insertedDocs
            - _id: 1
            - _id: 2
            - _id: 3
            - _id: 4
          session: session0
        result:
          insertedIds: {0: 1, 1: 2, 2: 3, 3: 4}
      - name: aggregate
        object: collection
        collectionOptions:
          # The driver overrides the collection's read pref with the
          # transaction's so count runs with Primary and succeeds.
          readPreference:
            mode: Secondary
        arguments:
          session: session0
          pipeline:
            - $match:
                _id: 1
            - $count: count
        result:
          - count: 1
      - name: find
        object: collection
        collectionOptions:
          readPreference:
            mode: Secondary
        arguments:
          session: session0
          batchSize: 3
        result: *insertedDocs
      - name: aggregate
        object: collection
        collectionOptions:
          readPreference:
            mode: Secondary
        arguments:
          pipeline:
            - $project:
                _id: 1
          batchSize: 3
          session: session0
        result: *insertedDocs
      - name: commitTransaction
        object: session0

    outcome:
      collection:
        data: *insertedDocs

  - description: primary readPreference

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            readPreference:
              mode: Primary
      - name: insertMany
        object: collection
        arguments:
          documents: &insertedDocs
            - _id: 1
            - _id: 2
            - _id: 3
            - _id: 4
          session: session0
        result:
          insertedIds: {0: 1, 1: 2, 2: 3, 3: 4}
      - name: aggregate
        object: collection
        collectionOptions:
          readPreference:
            mode: Secondary
        arguments:
          session: session0
          pipeline:
            - $match:
                _id: 1
            - $count: count
        result:
          - count: 1
      - name: find
        object: collection
        collectionOptions:
          readPreference:
            mode: Secondary
        arguments:
          session: session0
          batchSize: 3
        result: *insertedDocs
      - name: aggregate
        object: collection
        collectionOptions:
          readPreference:
            mode: Secondary
        arguments:
          pipeline:
            - $project:
                _id: 1
          batchSize: 3
          session: session0
        result: *insertedDocs
      - name: commitTransaction
        object: session0

    outcome:
      collection:
        data: *insertedDocs

  - description: secondary readPreference

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            readPreference:
              mode: Secondary
      - name: insertMany
        object: collection
        arguments:
          documents: &insertedDocs
            - _id: 1
            - _id: 2
            - _id: 3
            - _id: 4
          session: session0
        result:
          insertedIds: {0: 1, 1: 2, 2: 3, 3: 4}
      - name: aggregate
        object: collection
        collectionOptions:
          readPreference:
            mode: Primary
        arguments:
          session: session0
          pipeline:
            - $match:
                _id: 1
            - $count: count
        result:
          errorContains: read preference in a transaction must be primary
      - name: find
        object: collection
        collectionOptions:
          readPreference:
            mode: Primary
        arguments:
          session: session0
          batchSize: 3
        result:
          errorContains: read preference in a transaction must be primary
      - name: aggregate
        object: collection
        collectionOptions:
          readPreference:
            mode: Primary
        arguments:
          pipeline:
            - $project:
                _id: 1
          batchSize: 3
          session: session0
        result:
          errorContains: read preference in a transaction must be primary
      - name: abortTransaction
        object: session0

    outcome:
      collection:
        data: []

  - description: primaryPreferred readPreference

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            readPreference:
              mode: PrimaryPreferred
      - name: insertMany
        object: collection
        arguments:
          documents: &insertedDocs
            - _id: 1
            - _id: 2
            - _id: 3
            - _id: 4
          session: session0
        result:
          insertedIds: {0: 1, 1: 2, 2: 3, 3: 4}
      - name: aggregate
        object: collection
        collectionOptions:
          readPreference:
            mode: Primary
        arguments:
          session: session0
          pipeline:
            - $match:
                _id: 1
            - $count: count
        result:
          errorContains: read preference in a transaction must be primary
      - name: find
        object: collection
        collectionOptions:
          readPreference:
            mode: Primary
        arguments:
          session: session0
          batchSize: 3
        result:
          errorContains: read preference in a transaction must be primary
      - name: aggregate
        object: collection
        collectionOptions:
          readPreference:
            mode: Primary
        arguments:
          pipeline:
            - $project:
                _id: 1
          batchSize: 3
          session: session0
        result:
          errorContains: read preference in a transaction must be primary
      - name: abortTransaction
        object: session0

    outcome:
      collection:
        data: []

  - description: nearest readPreference

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            readPreference:
              mode: Nearest
      - name: insertMany
        object: collection
        arguments:
          documents: &insertedDocs
            - _id: 1
            - _id: 2
            - _id: 3
            - _id: 4
          session: session0
        result:
          insertedIds: {0: 1, 1: 2, 2: 3, 3: 4}
      - name: aggregate
        object: collection
        collectionOptions:
          readPreference:
            mode: Primary
        arguments:
          session: session0
          pipeline:
            - $match:
                _id: 1
            - $count: count
        result:
          errorContains: read preference in a transaction must be primary
      - name: find
        object: collection
        collectionOptions:
          readPreference:
            mode: Primary
        arguments:
          session: session0
          batchSize: 3
        result:
          errorContains: read preference in a transaction must be primary
      - name: aggregate
        object: collection
        collectionOptions:
          readPreference:
            mode: Primary
        arguments:
          pipeline:
            - $project:
                _id: 1
          batchSize: 3
          session: session0
        result:
          errorContains: read preference in a transaction must be primary
      - name: abortTransaction
        object: session0

    outcome:
      collection:
        data: []

  - description: secondary write only

    operations:
      - name: startTransaction
        object: session0
        arguments:
          options:
            readPreference:
              mode: Secondary
      - name: insertOne
        object: collection
        arguments:
          session: session0
          document:
            _id: 1
        result:
          insertedId: 1
      - name: commitTransaction
        object: session0

    outcome:
      collection:
        data:
          - _id: 1