Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Azure Cosmos DB not support MongoDB/Mongoose unique index?

Using a unique constraint in Mongoose like:

email: { type:String, unique:true }

doesn't seem to work. I can save several users with the same email.

Is there something I need to do to create a unique index?

like image 758
drew Avatar asked Mar 08 '23 11:03

drew


1 Answers

Unique indexes are not supported today, in the MongoDB API for Cosmos DB. You cannot specify unique:true when creating an index.

You'd need to implement this in your app tier.

EDIT - As pointed out, this was officially released as of November 2017, with the MongoDB API.

like image 104
David Makogon Avatar answered Apr 27 '23 00:04

David Makogon