Last active
October 15, 2018 13:01
-
-
Save nir1082/5a539e9fe15534e568a505b94c586399 to your computer and use it in GitHub Desktop.
[NCMB] 任意のクラスの全オブジェクトの値を更新するスクリプト
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
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