Saving Multiple Objects¶
This API stores multiple objects in a data table with a single request. Consider the following example, it demonstrates an API call which saves two objects in the Person
data table:
var persons = [
{ "name":"Joe", "age":24 },
{ "name":"Betty", "age":34 }
];
Backendless.Data.of( "Person" ).bulkCreate( persons )
.then( function( result ) {
console.log( "Objects have been saved" );
})
.catch( function( error ) {
console.log( "Server reported an error " + error );
})
The result of running the sample above is two objects saved in the database:
Backendless.Data.of( "TABLE-NAME" ).bulkCreate( [ {}, {}... ] )
.then( function( objectIDArray ) {
})
.catch( function( error ) {
});
function DataTypeX() {
this.propertyA = "";
this.propertyB = "";
}
Backendless.Data.of( DataTypeX ).bulkCreate( [ new DataTypeX(), new DataTypeX() ] )
.then( function( objectIDArray ) {
})
.catch( function( error ) {
});
where:
Argument | Description |
---|---|
DataTypeX |
function/class identifying the table where the objects will be stored. Instances of the class will be saved in the table. |
"TABLE-NAME" |
name of the table where the objects will be stored. |
Return Value¶
The API returns an array of object IDs for the objects created in the database. The order of the objectId
values in the response matches the order of the objects in the request.
The Backendless server implementation enforces the following rules:
Rules |
---|
All objects in the request must be of the same type. |
Objects in the request may have different set of properties. A property in the request body is ignored, if a column does not exist in the table. |
Objects in the request may have a unique objectId value that is not used in the database. |
Maximum number of objects in a single request is 100 for Backendless Cloud. It is configurable for Backendless Pro and Managed Backendless. |
A request will be rejected by the server, if there is no Create permission granted to the user identity/roles associated with the request. |