Create an index with MongoDb

前端 未结 5 1743
春和景丽
春和景丽 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:24

    I don't fully understand your problem but I feel it's very likely that you should use ensureIndex instead of createIndex as the latter always tries to create the index while the former will only ensure that it exists.

提交回复
热议问题