Skip to content

Instantly share code, notes, and snippets.

@vermaslal
Last active February 1, 2016 09:27
Show Gist options
  • Save vermaslal/c5ac234a25b8bb05b7ff to your computer and use it in GitHub Desktop.
Save vermaslal/c5ac234a25b8bb05b7ff to your computer and use it in GitHub Desktop.
Serialization on node js
function insertCollection(collection, callback) {
var coll = collection.slice(0); // clone collection
(function insertOne() {
var record = coll.splice(0, 1)[0]; // get the first record of coll and reduce coll by one
db.insert(record, function(err) {
if (err) { callback(err); return }
if (coll.length == 0) {
callback();
} else {
insertOne();
}
})
})();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment