Azure Cosmos DB是否不支持MongoDB/Mongoose唯一索引? [英] Does Azure Cosmos DB not support MongoDB/Mongoose unique index?

查看:71
本文介绍了Azure Cosmos DB是否不支持MongoDB/Mongoose唯一索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Mongoose中使用唯一约束,例如:

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?

推荐答案

当今,Cosmos DB的MongoDB API中不支持唯一索引.创建索引时不能指定unique:true.

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.

编辑-如前所述,该代码于2017年11月通过MongoDB API正式发布.

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

这篇关于Azure Cosmos DB是否不支持MongoDB/Mongoose唯一索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆