Last active
February 1, 2016 09:27
-
-
Save vermaslal/c5ac234a25b8bb05b7ff to your computer and use it in GitHub Desktop.
Serialization on node js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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