Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot call method 'create' of undefined #26

Open
ChristopherClint opened this issue May 10, 2015 · 0 comments
Open

TypeError: Cannot call method 'create' of undefined #26

ChristopherClint opened this issue May 10, 2015 · 0 comments

Comments

@ChristopherClint
Copy link

mongoose-fixture --fixture='all' --add

Loading fixtures from - mongoose-fixture-config.js
Established Connection MongoD (localhost:27017)
Mongoose-Fixture init schemas/models into conn

/usr/local/lib/node_modules/mongoose-fixture/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:286
      throw err;
            ^
TypeError: Cannot call method 'create' of undefined
at async.forEach.msg (/usr/local/lib/node_modules/mongoose-fixture/lib/BaseFixtureLoader.js:90:34)
at /usr/local/lib/node_modules/mongoose-fixture/node_modules/async/lib/async.js:99:13
at Array.forEach (native)
at _each (/usr/local/lib/node_modules/mongoose-fixture/node_modules/async/lib/async.js:32:24)
at Object.async.each (/usr/local/lib/node_modules/mongoose-fixture/node_modules/async/lib/async.js:98:9)
at /usr/local/lib/node_modules/mongoose-fixture/lib/BaseFixtureLoader.js:86:19
at module.exports (/var/www/dev/mysite/fixtures/Users.js:26:12)
at module.exports (/usr/local/lib/node_modules/mongoose-fixture/lib/BaseFixtureLoader.js:36:76)
at async.eachSeries.conn.close.disconnectMessage (/usr/local/lib/node_modules/mongoose-fixture/lib/MongooseFixture.js:67:17)
at iterate (/usr/local/lib/node_modules/mongoose-fixture/node_modules/async/lib/async.js:123:13)

cat fixtures/Users.js

var sha1 = require('sha1');

module.exports = function(mongoose, conn, callback){

// standard callback error
var error = null;

// create your data documents using object-literals
var fixture = [];

/*
 * Example of adding a data document/fixture item
 */
fixture.push({
    // by not defining an _id mongoose-fixture
    // will by default set a mongo ObjectID
    // defining one manually will override mongoDB
    username: 'admin',
    password: sha1('admin'),
    email: 'dev@clintagency.com',
    role: 'admin'
});

// mongoose-fixture expects implementor to return
// the callback passed in context
return callback(error, fixture);
};

cat schemas/UserSchema.js

module.exports = function(mongoose, conn) {
var UserSchema = new mongoose.Schema({
    _id       :  { type: String },
    username  :  { type: String, required: true },
    password  :  { type: String, required: true },
    email     :  { type: String, required: true, index: { unique: true } },
    role      :  { type: String, default: "normal" },
    token     :  { type: String, default: 0 },
    expired   :  { type: Date, default: Date.now },
    created   :  { type: Date, default: Date.now }
});

return {
    name: 'User',
    schema: UserSchema
};
}

cat mongoose-fixture-config.js

// Load the default object that helps manage a FixtureConfig
var FixtureConfig = require('mongoose-fixture').FixtureConfig;
var config = require('config');

// Create our fixture config with defined
// mongo-connection and file paths
var fixtureConfig = FixtureConfig({
mongoConnection:{
    'host': config.host,
    'port': config.port,
    'dbname': config.dbname
},
paths:{
    schemaPath:__dirname+'/schemas/',
    dataFixturePath:__dirname+'/fixtures/'
}
});


// Create a Listing of fixtures
var allFixtures = [
{
    itemName: 'User',
    schema: 'UserSchema',
    data:'Users',
    collection:'users'
},
];

// load fixture listings
fixtureConfig.fixtureListings.set('all', allFixtures);

// export the config
module.exports = fixtureConfig;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant