Reputation: 11285
I am trying to figure out how to validate the uniqueness of a field on a nested document across the board. Say I have the following schema:
var Store = new Schema({
name : String
, employees: [{name: string, email:string}]
});
Would there be anyway to ensure that the person's email was unique across all stores?
Upvotes: 0
Views: 330
Reputation: 51319
I believe that you can prevent duplicates in this case using a unique index in MongoDb: http://www.mongodb.org/display/DOCS/Indexes#Indexes-UniqueIndexes. If you try to insert an employee with an existing email address, you'll get an exception.
Upvotes: 2