Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1167

Code of ensureIndex and createIndex are inconsistent, yet the docs state they should be an alias of one another

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: MongoDB 3.2, MongoDB 3.4
    • Labels:
      None

      Description

      The documentation of MongoDB states that `ensureIndex` should be deprecated, and an alias of `createIndex`:

      db.collection.ensureIndex(keys, options)
      Deprecated since version 3.0.0: db.collection.ensureIndex() is now an alias for db.collection.createIndex().

      However, upon analysing the code, they seem to have clearly different functionality and `ensureIndex` does not in fact look like a simple alias for `createIndex`:

      createIndex
      https://github.com/mongodb/node-mongodb-native/blob/3.0.0/lib/db.js#L1029

      ensureIndex
      https://github.com/mongodb/node-mongodb-native/blob/3.0.0/lib/db.js#L1113

      Expected behaviour is that in light of the deprecation, `ensureIndex` should simply call `createIndex`.

      Currently there seem to be some users who still rely on the side effects present in `ensureIndex`, but they should probably receive a deprecation notice as well as instructions on how to migrate to using `createIndex` instead.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            adamreisnz Adam Reis
            Participants:
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: