ensure_index returns name of index even when index already exists

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Trivial - P5
    • 2.7
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Documentation states that ensure_index returns None if index already exists:

      Returns the name of the created index if an index is actually
      created. Returns ``None`` if the index already exists.

      In fact, it returns None only if index creation is cached, by pymongo itself. If it isn't cached but index already exists, it does not create it again, but still return name, not None:

              if not self.__database.connection._cached(self.__database.name,
                                                        self.__name, name):
                  return self.create_index(key_or_list, cache_for, **kwargs)
              return None
      

      (create_index never returns None, according to documentation).

            Assignee:
            Bernie Hackett
            Reporter:
            Konstantin Mochalov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: