저는 응용 프로그램을 개발 중이며 한 번에 많은 항목을 추가해야합니다.
node.js로 어떻게 할 수 있습니까? parse.com db에 객체 배열을 추가하는 방법은 무엇입니까?
insertAll("Foo", [objs...], ...)
같은 방법이 없습니다.
저는 응용 프로그램을 개발 중이며 한 번에 많은 항목을 추가해야합니다.
node.js로 어떻게 할 수 있습니까? parse.com db에 객체 배열을 추가하는 방법은 무엇입니까?
insertAll("Foo", [objs...], ...)
같은 방법이 없습니다.
응용 프로그램과 parse.com 사이를 연결하는 편리한 기능을 작성하십시오. https://parse.com/docs/rest#objects-creating : 당신은 한 번 반복 코드 (또는 디버그 광산)
var async = require('async');
var parseApp = require('node-parse-api').Parse;
var APP_ID = "";
var MASTER_KEY = "";
var parseApp = new Parse(APP_ID, MASTER_KEY);
function insertAll(class, objs, callback){
// create an iterator function(obj,done) that will insert the object
// with an appropriate group and call done() upon completion.
var insertOne =
(function(class){
return function(obj, done){
parseApp.insert(class, obj, function (err, response) {
if(err){ return done(err); }
// maybe do other stuff here before calling done?
var res = JSON.parse(response);
if(!res.objectId){ return done('No object id') };
done(null, res.objectId);
});
};
})(class);
// async.map calls insertOne with each obj in objs. the callback is executed
// once every iterator function has called back `done(null,data)` or any one
// has called back `done(err)`. use async.mapLimit if throttling is needed
async.map(objs, insertOne, function(err, mapOutput){
// complete
if(err){ return callback(err) };
// no errors
var objectIds = mapOutput;
callback(null, objectIds);
});
};
// Once you've written this and made the function accessible to your other code,
// you only need this outer interface.
insertAll('Foo', [{a:'b'}, {a:'d'}], function(err, ids){
if(err){
console.log('Error inserting all the Foos');
console.log(err);
} else {
console.log('Success!);
};
});
구문 분석이 그들의 서비스에 다중 삽입을 지원하기 위해 표시되지 않습니다를 작성해야합니다. 그래서 콜렉션을 반복하고 각각에 대해'.insert() '를 호출해야 할 것이다. –