talha-asad / mongoose-url-slugs

Create URL compatiable slugs on mongoose models, ensuring uniqueness.
MIT License
40 stars 22 forks source link

Slugs for subdocs #32

Open phex85 opened 7 years ago

phex85 commented 7 years ago

Hi,

I'm trying to get slugs for subdocs to work but I get an error, what I currently have is:

import mongoose from 'mongoose';
import URLSlugs from 'mongoose-url-slugs'

const Schema = mongoose.Schema;

const subTypeSchema = new Schema({
    name: {type: 'String', required: false},
});

subTypeSchema.plugin(URLSlugs('name'));

const productSchema = new Schema({
    name: { type: 'String', required: true },
    subtypes: [subTypeSchema],
});

productSchema.plugin(URLSlugs('name'));

export default mongoose.model('Product', productSchema);

I get the following error:

node_modules/mongoose-url-slugs/index.js:161 model.find(q, fields).exec(function(e, docs) {TypeError: : model.find is not a function

What am I doing wrong?

Node version 7.6.0 MongoDB shell version v3.4.4 Mongoose version ^4.4.20

talha-asad commented 7 years ago

Please submit a reproduction, you seem to be using ES6 syntax.