Pymongo / MongoDB: create index or ensure index?

后端 未结 5 2077
温柔的废话
温柔的废话 2020-12-07 22:30

I don\'t understand the difference between create_index and ensure_index in pymongo. On the MongoDB indexes page, it says

yo

5条回答
  •  借酒劲吻你
    2020-12-07 22:51

    Keep in mind that in Mongo 3.x ensureIndex is deprecated and should be discouraged.

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

    The same is in pymongo:

    DEPRECATED - Ensures that an index exists on this collection.

    Which means that you should always use create_index.

提交回复
热议问题