Create an index with MongoDb

前端 未结 5 1807
春和景丽
春和景丽 2021-02-13 03:20

I\'m beginner with MongoDB and i\'m trying some stuff. I want to store URL and to avoid duplicate URL I create an unique index on the url. Like that

collection.c         


        
5条回答
  •  天命终不由人
    2021-02-13 04:04

    Just stumbled over this question and there are some changes since Version 3.0.0

    db.collection.ensureIndex(keys, options)
    

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

    Creates an index on the specified field if the index does not already exist.

提交回复
热议问题