Reputation: 8137
I have a desire to check which fields in a schema
are set to unique
, similar to getting the indexes
for a schema
via MyCollection.collection.getIndexes()
. Can this information be found somewhere on the schema
object?
Upvotes: 0
Views: 204
Reputation: 1337
Try this:
var schema = new mongoose.Schema({
a: {
type: String,
unique: true
},
b: {
type: String
}
});
schema.tree.a.unique; // true
schema.tree.b.unique; // undefined
schema.path('a').options.unique; // true
schema.path('b').options.unique; // undefined
Upvotes: 2