Difference between db.collection.ensureIndex () and db.collection.createIndex () on mongodb

4

Is there a difference between creating an index using the ensureIndex() command and the createIndex() of MongoDB?

    
asked by hecnabae 04.12.2015 в 20:31
source

1 answer

4

As of version 3.0 of MongoDB, ensureIndex() has been deprecated in favor of createIndex() and is considered as an alias of the latter:

In summary, there is no difference if you are using version 3.0 , if you use ensureIndex() you would actually be implicitly calling createIndex() .

In the version 2.6 of ensureIndex() what was to create the index in the field specified only if it did not exist previously.

The version 3.0 of createIndex() creates the indexes in the collections .

    
answered by 04.12.2015 / 20:35
source