Skip to content

Instantly share code, notes, and snippets.

@tinyhappysteps
Created September 14, 2015 13:49
Show Gist options
  • Save tinyhappysteps/796f863db092dfafc1a1 to your computer and use it in GitHub Desktop.
Save tinyhappysteps/796f863db092dfafc1a1 to your computer and use it in GitHub Desktop.
Javascript / Node.js / MongoDB callback example
// 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