Closed viztastic closed 8 years ago
I should note that I have tried doing that to date, I have a "BookSchema" and a "chapterSchema" htat look something like this
var urlSlug = require('mongoose-url-slugs');
var bookSchema = new Schema({
"bookName" : {type:String},
"chapters": [chapterSchema]
})
var chapterSchema = new Schema({
"chapterName" : {type:String}
})
bookSchema.plugin(urlSlug("bookName"));
chapterSchema.plugin(urlSlug("chapterName"));
This seems to return an error The example is extremely simplified, but hopefully it conveys what I am trying to do.
I have also tried playing with settings like chapterSchema.plugin(urlSlug("chapterName",{index:false,index_required:false}));
{ [MongoError: E11000 duplicate key error index: salis-test.contents.$contents.slug_1 dup key: { : null }] name: 'MongoError', message: 'E11000 duplicate key error index: salis-test.contents.$contents.slug_1 dup key: { : null }', driver: true, code: 11000, index: 0, errmsg: 'E11000 duplicate key error index: salis-test.contents.$contents.slug_1 dup key: { : null }', getOperation: [Function], toJSON: [Function], toString: [Function] }
Please empty the collections first and then try again. The error message generally pops up if you already have documents that don't obey the index definitions.
Hi @talha-asad , thanks for the response, I did the following steps:
$ mongo [DatabaseName]
$ db.[collectionName].remove({})
$ db.[collectionName].drop()
Then I re-ran the node app and I got this error instead:
What version of mongoose, mongodb and node are you using. I'll try and reproduce this error.
HI @talha-asad
Sorry for the belated response:
Mongoose Version: 4.3.4 NodeJS version: 4.2.1 MongoDB version: 3.0.5
Much appreciated!
Hi Talha,
Thanks for this module, it's great. I have a particular use case in mind:
I have a document (e.g. "Book") I currently use mongoose-url-slugs to create a slug for it. But now I have sub documents (e.g. Chapters within the book) that I'd also like to create a slug for each individual chapter.
Example Schema
Is there a way to achieve this?