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

      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.

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

              Created:
              Updated:
              Resolved: