@Unique doesn't work in MongoDB
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
TypeORM version:
[x] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
@Entity()
export class PackageSettings implements IPackageSettings {
@ObjectIdColumn() id: ObjectID;
@Column({ unique: true })
@IsString()
@IsNotEmpty()
name: string;
@Column('simple-json') value: object;
}
and
@Entity()
@Unique(['name'])
export class PackageSettings implements IPackageSettings {
@ObjectIdColumn() id: ObjectID;
@Column()
@IsString()
@IsNotEmpty()
name: string;
@Column('simple-json') value: object;
}
No index unique created in mongodb and no error thrown when I try to save multiple objects with same name attribute.
Is decorator @Unique only RDBMS-specific ?
Issue Analytics
- State:
- Created 5 years ago
- Comments:15 (11 by maintainers)
Top Results From Across the Web
Mongoose Unique index not working! - Stack Overflow
1 . Add unique: true to the attributes. let schema = new mongoose. · 2 . Drop the collection - for example role...
Read more >Mongoose Unique Not Working - DEV Community
The first- and best imho- is to use mongoose.connection.syncIndexes() to reconstruct the indexes of all collections to match all schemas (it ...
Read more >Unique partial index is not working with mongoose on email
I am using mongodb version 4.4.8 and mongoose version 5.5.9. I have an user schema and this is how i define it
Read more >Mongoose Unique Not Working?! | Have Fun Learning
1. DB already messed up. If there are already duplicated emails in your collections, then the new constraints won't work. · 2. Index...
Read more >Unique is not working · Issue #5050 · Automattic/mongoose
HI below is my Schema in which unique is not working const user = new Schema({ userName: { type: String, required: true, unique:...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You need to put
synchronize: true
in your connection options. This flag executes indices synchronization@Index({ unique: true })
I checked on the version 0.2.3, it’s works for meBut, it’s very strange that there are 2 syntaxes
@Column({ unique: true })
and@Index({ unique: true })
I use mongodb version 3.4.7