Created
September 14, 2015 13:49
-
-
Save tinyhappysteps/796f863db092dfafc1a1 to your computer and use it in GitHub Desktop.
Javascript / Node.js / MongoDB callback example
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 with callback | |
var getPayerIDs = function(db, callback) { | |
console.log("is db null?:" + (db == null)); | |
var condition = new Object(); | |
condition.iap_status = "success"; | |
condition.receipt = {$in: [/^129/, /GPA./]}; | |
db.collection('android_uc_iap').distinct("device_id", condition, function (err, docs) { | |
callback(docs); | |
}); | |
}; | |
// Calling it | |
getPayerIDs(db, function(theResult){ | |
console.log(dbname); | |
console.log(theResult); | |
payers = payers.concat(theResult); | |
numberCollected++; | |
if (numberCollected == 12) { // async so need a way to know when it’s done | |
payers = unique(payers); | |
console.log(‘Print unique payers'); | |
console.log(payers); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment