Uploaded image for project: 'MongoDB Shell'
  1. MongoDB Shell
  2. MONGOSH-1478

dropIndex() not working with readPreference=secondary in mongosh

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.0.0
    • Affects Version/s: 1.8.0, 1.9.1
    • Component/s: Shell API
    • None
    • Environment:
      Issue reproducible with:
      Mongosh versions: 1.9.1 and 1.8.0 standalone and in Compass
    • 8
    • Iteration Hagryphus, Iteration Iguanodon
    • Needed
    • Hide

      Breaking Change

      According to https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#use-of-read-preferences-with-commands, mongosh was not behaving properly when calling runCommand.

      In the current mongosh version, runCommand is considering the readPreference specified either by using setReadPref or in the connection string. This was the main issue of some inconsistent behaviours.

      In the new mongosh version, runCommand is not going to consider anymore the readPreference provided globally, either by setReadPref or in the connection string. It will accept a new parameter, an object of type RunCommandOptions:

      export declare type RunCommandOptions = {
          /** Specify ClientSession for this command */
          session?: ClientSession;
          /** The read preference */
          readPreference?: ReadPreferenceLike;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          willRetryWrite?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          omitReadPreference?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          writeConcern?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          explain?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          readConcern?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          collation?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          maxTimeMS?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          comment?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          retryWrites?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          dbName?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          authdb?: any;
          /** @deprecated This is an internal option that has undefined behavior for this API */
          noResponse?: any;
          /* Excluded from this release type: bypassPinningCheck */
      } & BSONSerializeOptions;
      

      For example, if we want to run `hello` with a readPreference `secondaryPreferred` we would do:

      Enterprise replset [primary] test> db.runCommand({ hello: 1 }, { readPreference: 'secondaryPreferred' })
      {
        topologyVersion: {
          processId: ObjectId("64dccf2b9129f981534d8598"),
          counter: Long("4")
        },
        hosts: [ 'localhost:27017', 'localhost:27018', 'localhost:27019' ],
        setName: 'replset',
        setVersion: 1,
        isWritablePrimary: false,
        secondary: true, <<< HAS BEEN READ FROM A SECONDARY
        primary: 'localhost:27017',
        me: 'localhost:27018', << FROM THIS SECONDARY
      

      If no readPreference is specified, `primary` will be used, ignoring any other global configuration, including setReadPref or readPreference in the URL.

      Show
      Breaking Change According to https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection.rst#use-of-read-preferences-with-commands , mongosh was not behaving properly when calling runCommand. In the current mongosh version, runCommand is considering the readPreference specified either by using setReadPref or in the connection string. This was the main issue of some inconsistent behaviours. In the new mongosh version, runCommand is not going to consider anymore the readPreference provided globally, either by setReadPref or in the connection string. It will accept a new parameter, an object of type RunCommandOptions: export declare type RunCommandOptions = { /** Specify ClientSession for this command */ session?: ClientSession; /** The read preference */ readPreference?: ReadPreferenceLike; /** @deprecated This is an internal option that has undefined behavior for this API */ willRetryWrite?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ omitReadPreference?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ writeConcern?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ explain?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ readConcern?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ collation?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ maxTimeMS?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ comment?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ retryWrites?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ dbName?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ authdb?: any; /** @deprecated This is an internal option that has undefined behavior for this API */ noResponse?: any; /* Excluded from this release type: bypassPinningCheck */ } & BSONSerializeOptions; For example, if we want to run `hello` with a readPreference `secondaryPreferred` we would do: Enterprise replset [primary] test> db.runCommand({ hello: 1 }, { readPreference: 'secondaryPreferred' }) { topologyVersion: { processId: ObjectId( "64dccf2b9129f981534d8598" ), counter: Long ( "4" ) }, hosts: [ 'localhost:27017' , 'localhost:27018' , 'localhost:27019' ], setName: 'replset' , setVersion: 1, isWritablePrimary: false , secondary: true , <<< HAS BEEN READ FROM A SECONDARY primary: 'localhost:27017' , me: 'localhost:27018' , << FROM THIS SECONDARY If no readPreference is specified, `primary` will be used, ignoring any other global configuration, including setReadPref or readPreference in the URL.

      Problem Statement/Rationale

      dropIndex() not working with readPreference=secondary in mongosh

            Assignee:
            kevin.mas@mongodb.com Kevin Mas Ruiz
            Reporter:
            sweta.attri@mongodb.com Sweta Attri
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: