Wednesday, 6 January 2016

mongoose question

Bit of a newbie here with Mongoose but I'm having difficulty ensuring a document is unique using two fields, title and owner(user ID).found this on stackoverflow but it doesn't seem to work in my case.Can anyone point my in the right direction? Below is my schema, thankslet DocsSchema = new Schema({title: { type: String, required: true, index: true },desc: { type: String },created: { type: Date, default: Date.now },updated: { type: Date },owner: { type: Schema.Types.ObjectId, ref: 'User', index: true },chapters: [ Chapter.schema ]});DocsSchema.index({ title: 1, owner: 1 }, { unique: true });

Submitted January 07, 2016 at 01:04AM by _httpete_

No comments:

Post a Comment