So I installed this plugin https://www.npmjs.com/package/mongoose-seeder
It came with mongoose in sub-directory, so I deleted that directory because I have mongoose already in node_modules and it was giving me errors until deleted. The app runs without error, however nothing is created in the myappname-dev database.
As per instructions, created a basic json file (data.json) in /config for mongoose-seeder to parse:
{
"categories": {
"_model": "Category",
"title": "Cat1"
}
}
In server.js:
var init = require('./config/init')(),
config = require('./config/config'),
mongoose = require('mongoose'),
chalk = require('chalk');
var seeder = require('mongoose-seeder'),
data = require('./config/data.json');
// Bootstrap db connection
var db = mongoose.connect(config.db, function(err) {
if (err) {
console.error(chalk.red('Could not connect to MongoDB!'));
console.log(chalk.red(err));
}
seeder.seed(data, function(err, dbData) { });
});
Category model:
'use strict';
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
/**
* Category Schema
*/
var CategorySchema = new Schema({
title: {
type: String,
default: 'Untitled'
}
});
mongoose.model('Category', CategorySchema);
I am using the meanjs project template, in general I am new to MEAN and having a hard time figuring out how to seed initial data. Another strange thing I noticed is when I create new users in the default meanjs app, they don't appear to be in the users collection of the myappname-dev database.