MongoDB :: MongoIds在集合中是唯一的吗? [英] MongoDB :: are MongoIds unique across collections?

查看:89
本文介绍了MongoDB :: MongoIds在集合中是唯一的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道:Mongo ID在同一个数据库的不同集合中可以具有相同的值吗?

I was wondering: can Mongo IDs have the same value in different collections in the same database?

谢谢

推荐答案

_id的唯一性约束是每个集合,因此是的-每个集合一次可以出现一个相同的ID.

The uniqueness constraint for _id is per collection, so yes - one and the same ID can occur once per Collection.

但是,即使不是不可能,两次生成同一ID的可能性很小.因此,要实现此目的,您必须手动插入重复的ID.

It's however very unlikely, if not impossible, for the same ID to be generated twice. So in order for this to happen you would have to manually insert duplicate IDs.

这篇关于MongoDB :: MongoIds在集合中是唯一的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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