The Database Hub is home for developers who want to clone, connect, and share databases and build apps together. Cloning a database allows you to copy it to your account and give a great start to your project.
This is a public database to demonstrate how to import a set of parse objects to a Parse Server database.
This is a live example for this Gist that shows how to import data to a Parse Server database.
In order to run this example, first create a data.json
file like this:
{
"className": "ExampleClass",
"rows": [
{ "ExampleColumnA": "row1columnA", "ExampleColumnB": "row1columnB" },
{ "ExampleColumnA": "row2columnA", "ExampleColumnB": "row2columnB"}
]
}
Then you just need to run a curl command like this:
curl -X POST \
-H "X-Parse-Application-Id: LL9oIdzIkmwl5xyowQQu0fTmXyUWfet9RuAzwHfj" \
-H "X-Parse-REST-API-Key: R3S8PYQKuzeV4c8MUeO5ved46C50MEp56boDHW1O" \
-H "Content-Type: application/json" \
-d @data.json \
https://parseapi.back4app.com/functions/import
You can see the imported rows by checking the ExampleClass.
Use the clone button on the top of this page to clone this example to your account and see how it works. Basically it is running Parse Server 3.9.0 and it was added a main.js
file with the following cloud code function:
Parse.Cloud.define('import', async request => {
const className = request.params.className;
const rows = request.params.rows;
const MyClass = Parse.Object.extend(className);
var myClassObjects = [];
for (let i = 0; i < rows.length; i++) {
const myClassObject = new MyClass();
for (const column in rows[i]) {
myClassObject.set(column, rows[i][column]);
}
myClassObjects.push(myClassObject);
}
try {
await Parse.Object.saveAll(myClassObjects);
} catch (e) {
throw new Error(`Import failed: ${e}`);
}
return `Successfully imported ${myClassObjects.length} rows into ${className} class`;
});
We use cookies to provide our services and for analytics and marketing. To find out more about our use of cookies, please see our Terms of Service and Privacy Policy . By continuing to browse our website, you agree to our use of cookies.