Skip to content

Instantly share code, notes, and snippets.

@mosluce
Last active December 27, 2015 14:05
Show Gist options
  • Save mosluce/afe38de059468043d851 to your computer and use it in GitHub Desktop.
Save mosluce/afe38de059468043d851 to your computer and use it in GitHub Desktop.
var i = 0;
Check.updataPartly = function(foodName, partly, numBig, numSamll, callback){
//打開資料庫
mongodb.open(function(err,db){
if (err) {
return callback(err);
}
//讀取checks的集合
db.collection('checks',function(err,collection){
if (err) {
mongodb.close();
return callback(err);
}
collection.update({
"foodName":foodName[i]
},{//修改
$set: {partly: partly-(numSamll[i]+numBig[i])}
},function(err) {
mongodb.close();
if (err) {
return callback(err);
}
i++;
if(foodName[i]) {
Check.updataPartly(foodName, partly, numBig, numSamll, callback);
} else {
callback(null);
}
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment