lykmapipo / mongoose-faker

mongoose plugin to generate fake model data
MIT License
15 stars 4 forks source link

First param to `schema.plugin()` must be a function, got "object" #7

Open geetikaTiwari007 opened 5 years ago

geetikaTiwari007 commented 5 years ago

I tried your code but getting this error as mongoose.plugin needs function as first param but we are passing object. Please guide how to resolve the same.

lykmapipo commented 5 years ago

@geetikaTiwari007

Try follow:

const mongoose = require('mongoose');
const faker = require('mongoose-faker');

const UserSchema = new mongoose.Schema({
 name: { type: String, fake: f => f.name.findName() }
});
UserSchema.plugin(faker);

const User = mongoose.model('User', UserSchema);
const user = User.fake();
// => {_id: ..., name: ...}
maheraldous commented 3 years ago

@lykmapipo It not working.