andrejewski / fakegoose

Faker + Mongoose
ISC License
32 stars 8 forks source link

doc[path] = typeof value === 'function' ^ TypeError: Cannot set property 'occupation' of undefined #3

Closed isaklafleur closed 6 years ago

isaklafleur commented 7 years ago

Hi!

I'm trying to run the command from the folder where fakegoose-celebrity.js is located: fakegoose fakegoose-celebrity.js --count 10 --seed mongodb://localhost:27017/mongoose-movies

I have installed fakegoose locally and globally..

Here is the fakegoose-celebrity.js file

const mongoose = require('mongoose');
const fakegoose = require('fakegoose');

const Schema = mongoose.Schema;

const CelebritySchema = new Schema({
  name: {
    type: String,
    fake: 'name.firstName',
    required: [true, 'Please enter the celebrity\'s name'],
  },
  occupation: {
    type: String,
    fake: 'name.firstName',
  },
  catchPhrase: {
    type: String,
    fake: 'name.firstName',
  },
});

CelebritySchema.plugin(fakegoose);
module.exports = mongoose.model('Celebrity', CelebritySchema);

// fakegoose fakegoose-seed.js --count 10 --seed mongodb://localhost:27017/mongoose-movies

I get this error message:

  bin git:(master) ✗ fakegoose fakegoose-seed.js --count 10 --se
ed mongodb://localhost:27017/mongoose-movies
/Users/isaklafleur/Dropbox/Isak/Coding/IronHack/module2/lab-mongo
ose-movies/node_modules/fakegoose/fakegoose.js:166
    doc[path] = typeof value === 'function'
              ^

TypeError: Cannot set property 'occupation' of undefined
    at /Users/isaklafleur/Dropbox/Isak/Coding/IronHack/module2/la
b-mongoose-movies/node_modules/fakegoose/fakegoose.js:166:15
    at Array.reduce (native)
    at makeJsonDocument (/Users/isaklafleur/Dropbox/Isak/Coding/I
ronHack/module2/lab-mongoose-movies/node_modules/fakegoose/fakego
ose.js:164:16)
    at _seed (/Users/isaklafleur/Dropbox/Isak/Coding/IronHack/mod
ule2/lab-mongoose-movies/node_modules/fakegoose/fakegoose.js:155:
18)
    at Object.seed (/Users/isaklafleur/Dropbox/Isak/Coding/IronHa
ck/module2/lab-mongoose-movies/node_modules/fakegoose/fakegoose.j
s:143:26)
    at Function.seed (/Users/isaklafleur/Dropbox/Isak/Coding/Iron
Hack/module2/lab-mongoose-movies/node_modules/fakegoose/index.js:
15:22)
    at Object.<anonymous> (/usr/local/lib/node_modules/fakegoose/
bin/fakegoose.js:41:9)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.runMain (module.js:604:10)
    at run (bootstrap_node.js:393:7)
    at startup (bootstrap_node.js:150:9)
    at bootstrap_node.js:508:3
adriennn commented 6 years ago

got the same error, ended up using fakerjs directly:

var MongoClient = require('mongodb').MongoClient
var test        = require('assert')
var ObjectId    = require('mongodb').ObjectID
var faker       = require('faker')

MongoClient.connect('mongodb://localhost:27017/yourdatabase', function(err, db) {

  test.equal(err, null)

  let collection = db.collection('Employees')
  let documents = []

  for ( i=0; i < 100; i++ ) {

    docsuments[i] = {
      name: faker.name.findName(),
      email: faker.internet.email(),
      core: faker.company.bsBuzz(),
      url: faker.fake("www.{{internet.domainSuffix}}.{{name.suffix}}"),
      phone: faker.phone.phoneNumber(),
      id: faker.random.uuid(),
      position: faker.name.jobType()
    }
  }

  collection.insertMany(documents, function(err, response) {
    test.equal(err, null)
    console.log(response.insertedCount)
    db.close()
  })
})

Then simply save this as a JS file and run it with; node yourfile.js

andrejewski commented 6 years ago

Fixed by https://github.com/andrejewski/fakegoose/pull/4