Skip to content

Instantly share code, notes, and snippets.

@andypham
Created May 5, 2015 18:25
Show Gist options
  • Save andypham/799291b7f691a92af9d5 to your computer and use it in GitHub Desktop.
Save andypham/799291b7f691a92af9d5 to your computer and use it in GitHub Desktop.
sails mongo topology was destroyed exception - sails-mongo/lib/collection.js
Collection.prototype.insert = function insert(values, cb) {
var self = this;
// Normalize values to an array
if(!Array.isArray(values)) values = [values];
// Build a Document and add the values to a new array
var docs = values.map(function(value) {
return new Document(value, self.schema).values;
});
this.connection.db.collection(this.identity).insert(docs, function(err, results) {
if(err) return cb(err);
setTimeout(function() {
cb(null, utils.rewriteIds(results.ops, self.schema));
}, 10);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment