Skip to content

Instantly share code, notes, and snippets.

@kyriesent
Created August 5, 2014 18:02
Show Gist options
  • Save kyriesent/c7cb0f0df594217801d6 to your computer and use it in GitHub Desktop.
Save kyriesent/c7cb0f0df594217801d6 to your computer and use it in GitHub Desktop.
var acl = require('../routes/middleware/acl');
var mongoose = require('mongoose');
// var config = require('../libs/configurator'); don't need this
var config = require('../libs/configurator');
var async = require('async');
require('../models')(mongoose);
// mongoose.models.Works.find({}).exec(function (err, works) { <-- Work should be singular, as in below
mongoose.models.Work.find({}).exec(function (err, works) {
async.each(works, function (work, cb) {
mongoose.models.Group.find({"featured._work": work._id}, function (err, groups) {
if (err !== undefined) {
throw err
} else {
work.featuredIn = _.map(groups, function(group) {
_group: group._id.toString()
});
/*
You need to run mongoose.models.Work.update() here after you've confirmed that there are
matching groups. As is this will not actually persist your changes to the database
*/
}
});
}, function (err) {
process.exit();
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment