Skip to content

Instantly share code, notes, and snippets.

@thepeopleseason
Created July 22, 2014 11:20
Show Gist options
  • Save thepeopleseason/0786af60bea090ab487e to your computer and use it in GitHub Desktop.
Save thepeopleseason/0786af60bea090ab487e to your computer and use it in GitHub Desktop.
Mongo Seed Error
vagrant@habitrpg:/vagrant$ node ./src/seed.js
Failed to load c++ bson extension, using pure JS version
info: tavern=null, cb=function (err){
if (err) throw err;
logging.info("Done initializing database");
mongoose.disconnect();
}
/vagrant/node_modules/mongoose/lib/utils.js:413
throw err;
^
MongoError: E11000 duplicate key error index: habitrpg.groups.$_id_ dup key: { : "habitrpg" }
at Object.toError (/vagrant/node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:110:11)
at /vagrant/node_modules/mongoose/node_modules/mongodb/lib/mongodb/collection/core.js:212:24
at Server.Base._callHandler (/vagrant/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:442:41)
at /vagrant/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:485:18
at MongoReply.parseBody (/vagrant/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
at null.<anonymous> (/vagrant/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:443:20)
at emit (events.js:95:17)
at null.<anonymous> (/vagrant/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:191:13)
at emit (events.js:98:17)
at Socket.<anonymous> (/vagrant/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection.js:418:22)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:748:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:410:10)
at emitReadable (_stream_readable.js:406:5)
at readableAddChunk (_stream_readable.js:168:9)
at Socket.Readable.push (_stream_readable.js:130:10)
at TCP.onread (net.js:528:21)
vagrant@habitrpg:/vagrant$ node ./src/seed.js
Failed to load c++ bson extension, using pure JS version
info: strictMode=throw, selected=undefined, shardval=undefined, saveError=undefined, validationError=undefined, adhocPaths=undefined, removing=undefined, inserting=undefined, version=undefined, , _id=undefined, populate=undefined, populated=undefined, wasPopulated=false, scope=undefined, members=init, invites=init, privacy=init, chat=init, memberCount=init, challengeCount=init, challenges=init, quest.active=init, quest.progress.collect=init, __v=init, type=init, name=init, leader=init, _id=init, , __v=true, members=true, invites=true, privacy=true, chat=true, memberCount=true, challengeCount=true, challenges=true, quest.active=true, quest.progress.collect=true, type=true, name=true, leader=true, _id=true, , , stateNames=[require, modify, init, default], ownerDocument=undefined, fullPath=undefined, isNew=false, errors=undefined, _maxListeners=0, members=[], invites=[], privacy=public, chat=[], memberCount=0, challengeCount=0, challenges=[], active=false, , __v=0, type=guild, name=HabitRPG, leader=9, _id=habitrpg, save=[function (next) {
// validate all document arrays.
// we keep the error semaphore to make sure we don't
// call `save` unnecessarily (we only need 1 error)
var subdocs = 0
, error = false
, self = this;
// check for DocumentArrays
var arrays = this.$__.activePaths
.map('init', 'modify', function (i) {
return self.getValue(i);
})
.filter(function (val) {
return val && val instanceof DocumentArray && val.length;
});
if (!arrays.length)
return next();
arrays.forEach(function (array) {
if (error) return;
// handle sparse arrays by using for loop vs array.forEach
// which skips the sparse elements
var len = array.length
subdocs += len;
for (var i = 0; i < len; ++i) {
if (error) break;
var doc = array[i];
if (!doc) {
--subdocs || next();
continue;
}
doc.save(handleSave);
}
});
function handleSave (err) {
if (error) return;
if (err) {
self.$__.validationError = undefined;
return next(error = err);
}
--subdocs || next();
}
}, function checkForExistingErrors(next) {
// if any doc.set() calls failed
var err = this.$__.saveError;
if (err) {
this.$__.saveError = null;
next(err);
} else {
next();
}
}, function validation(next) {
return this.validate(next);
}, function (next){
removeDuplicates(this);
this.memberCount = _.size(this.members);
this.challengeCount = _.size(this.challenges);
next();
}], save=[], save=function () {
var self = this
, hookArgs // arguments eventually passed to the hook - are mutable
, lastArg = arguments[arguments.length-1]
, pres = this._pres[name]
, posts = this._posts[name]
, _total = pres.length
, _current = -1
, _asyncsLeft = proto[name].numAsyncPres
, _next = function () {
if (arguments[0] instanceof Error) {
return handleError(arguments[0]);
}
var _args = Array.prototype.slice.call(arguments)
, currPre
, preArgs;
if (_args.length && !(arguments[0] == null && typeof lastArg === 'function'))
hookArgs = _args;
if (++_current < _total) {
currPre = pres[_current]
if (currPre.isAsync && currPre.length < 2)
throw new Error("Your pre must have next and done arguments -- e.g., function (next, done, ...)");
if (currPre.length < 1)
throw new Error("Your pre must have a next argument -- e.g., function (next, ...)");
preArgs = (currPre.isAsync
? [once(_next), once(_asyncsDone)]
: [once(_next)]).concat(hookArgs);
return currPre.apply(self, preArgs);
} else if (!proto[name].numAsyncPres) {
return _done.apply(self, hookArgs);
}
}
, _done = function () {
var args_ = Array.prototype.slice.call(arguments)
, ret, total_, current_, next_, done_, postArgs;
if (_current === _total) {
ret = fn.apply(self, args_);
total_ = posts.length;
current_ = -1;
next_ = function () {
if (arguments[0] instanceof Error) {
return handleError(arguments[0]);
}
var args_ = Array.prototype.slice.call(arguments, 1)
, currPost
, postArgs;
if (args_.length) hookArgs = args_;
if (++current_ < total_) {
currPost = posts[current_]
if (currPost.length < 1)
throw new Error("Your post must have a next argument -- e.g., function (next, ...)");
postArgs = [once(next_)].concat(hookArgs);
return currPost.apply(self, postArgs);
}
};
if (total_) return next_();
return ret;
}
};
if (_asyncsLeft) {
function _asyncsDone (err) {
if (err && err instanceof Error) {
return handleError(err);
}
--_asyncsLeft || _done.apply(self, hookArgs);
}
}
function handleError (err) {
if ('function' == typeof lastArg)
return lastArg(err);
if (errorCb) return errorCb.call(self, err);
throw err;
}
return _next.apply(this, arguments);
}, , cb=function (err){
if (err) throw err;
logging.info("Done initializing database");
mongoose.disconnect();
}
info: Done initializing database
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment