I am having an issue with the Mongoose fixture loader and I am not sure what is wrong.
When I load my data according to docs such as:
var data = { User: [{name: 'Alex'}, {name: 'Bob'}] };
It does not load. Exploring the code I see that in this file there is an async.forEach iterator which doesn't seem to get triggered. Creating a simple file to test I still cannot get this to work as it should. Evidently the console should print 'User' but it does not. Can someone shed some light on what the issue might be? Note that while I have phrased my question about the async, ultimately I am trying to get the mongoose loader to work so I need to stay within their code structure.
var async = require('async');
var data = { User: [{name: 'Alex'}, {name: 'Bob'}] };
var iterator = function(modelName, next){
// not working
console.log(modelName);
next();
};
async.forEach(data, iterator, function() { });
The pow-mongoose-fixtures module in the NPM repository contains a bug (see bug report).
Your code contains the same bug:
async.forEach(data, ...)
forEach() operates on arrays, but data is an object. In case of the module, it was fixed by using Object.keys() to get an array of keys. You could use it too:
async.forEach(Object.keys(data), ...);
To get mongoose-fixtures working, install the GitHub version:
npm install git://github.com/powmedia/mongoose-fixtures.git
There's a couple of changed you need to make to your code as well:
var fixtures = require('mongoose-fixtures'); // renamed from 'pow-mongoose-fixtures'
var client = mongoose.connect(...);
...
fixtures.load(data, client); // need to pass the client object