Skip to content

Instantly share code, notes, and snippets.

@nir1082
Last active October 15, 2018 13:01
Show Gist options
  • Save nir1082/5a539e9fe15534e568a505b94c586399 to your computer and use it in GitHub Desktop.
Save nir1082/5a539e9fe15534e568a505b94c586399 to your computer and use it in GitHub Desktop.
[NCMB] 任意のクラスの全オブジェクトの値を更新するスクリプト
module.exports = function saveData(req, res) {
var className = req.body.className;
var fieldName = req.body.fieldName;
var value = req.body.value;
var NCMB = require('ncmb');
var ncmb = new NCMB('APPLICATION_KEY', 'CLIENT_KEY');
var dataStore = ncmb.DataStore(className);
dataStore.fetchAll()
.then(function(items){
const promises = [];
for (var i = 0; i < items.length; i++) {
items[i].set(fieldName, value);
promises.push(items[i].update());
}
Promise.all(promises)
.then((ary) => {
res.send("Succeed: " + className + "." + fieldName + " = " + value + "(" + items.length + ")");
});
})
.catch(function(error){
console.log(error);
res.status(500).send("Error: " + error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment