Compound Unique indexes
See original GitHub issueFeature Request:
A cool to have compound unique indexes in a schema for instance.
var Schema = new Schema({
created: {
type: Date,
default: Date.now
},
product_slug : {
type: String,
index: true
},
store_slug: {
type: String
index: true
}
});
Schema.unique({store_slug : {product_slug : 1}});
So product_slug must be unique among all objects with the same store_slug.
This definitely could be achieved with a mongoose plugin however I think this could give mongoose a lot of power right out of the box and could be included.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6
Top Results From Across the Web
Unique Indexes — MongoDB Manual
A unique index ensures that the indexed fields do not store duplicate values; i.e. enforces uniqueness for the indexed fields. By default, MongoDB...
Read more >How to create a composite unique index (not as a primary key ...
1. Open the table in Design View. · 2. Click Indexes button. · 3. Enter the first column for the index. · 4....
Read more >MongoDB Unique Index
When a unique index contains more than one field, it is called a unique compound index. A unique compound index ensures the uniqueness...
Read more >Unique and non-unique indexes - IBM
Unique indexes are indexes that help maintain data integrity by ensuring that no rows of data in a table have identical key values....
Read more >mongodb compound index unique if A and B both are same
mongodb compound index unique if A and B both are same · @PrathapReddy I'm using mongoosejs.com/docs/api/schema.html#schema_Schema-index, a third ...
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 Free
Top 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
Schema.index({ store_slug: 1, product_slug: 1 }, { unique: true });
https://docs.mongodb.org/manual/tutorial/create-a-unique-index/#unique-compound-index@vkarpov15 Thank you for the clarifiation!