mongodb - 为什么我不能在不同的 mongodb 集合中有类似的索引(索引)?
问题描述
我正在为我正在从事的一些项目使用 Nest js,我决定使用 Typeorm。我知道直接使用 Mongoose 可能会更好,但我希望将来可以选择轻松迁移到 Postgress 或 MySQL。
根据我对 MongoDB 的理解,我只能在每个集合中拥有一个唯一的索引,但我可以在不同的集合、同一个数据库中拥有同名的索引。如果我错了,请纠正我。
我有两个实体Foo
和Bar
@Entity()
export class Foo {
// Other columns
@Column()
@Index({ unique: true })
email: string;
// Other columns
}
@Entity()
export class Bar {
// Other columns
@Column()
@Index({ unique: true })
email: string;
// Other columns
}
在我的 typeorm 配置中,我已经启用,synchronization
因为我处于开发模式。我希望创建两个实体/集合而不会失败,但是当我启动我的应用程序时出现错误
MongoError: Index with name: [INDEX_NAME] already exists with a different name
在使用 MongoDB Compass 检查数据库时,我发现提到的 [INDEX_NAME] 是Foo
实体的电子邮件索引。
有什么我想念的东西,因为我无法完全理解它吗?
解决方案
推荐阅读
- sql - BigQuery:从数组创建表
- php - php更改日期的顺序
- python - “while”循环过早退出(python 3)
- mysql - MySQL子查询作为别名 - 未知列错误
- c# - AutoMapper 不映射嵌套的复杂类型
- ffmpeg - 使用 ffmpeg 将 DTS 转换为 AAC 将语音音频向右移动
- path - 路径问题 - POSIX HFS 无法获取文件夹
- java - Firebase 数据库分页滚动动作
- bash - Bash - 如果主域在文件 A(或管道)中,则从文件 B 中删除域/子域
- android - 将可见性设置为 GONE 不会隐藏 imageView