Reading and Writing data
This guide will teach you how to create, read, update, and delete data objects on Back4app using the Parse SDK. Data storage on Back4app revolves around the Parse.Object class, which allows you to store key-value pairs of JSON-compatible data, providing flexibility and simplicity in data management.
Objectives
- Understand how to perform data manipulation (CRUD) on Back4app using Parse SDK.
- Learn how to set up and use the Parse SDK across different platforms.
Prerequisites
App on Back4app: You need an app created on Back4app.
Parse SDK Installation:
1 - Creating Parse Objects
To store data in Back4app, you need to create a ParseObject associated with a specific class. For example, in a soccer-related application, you could create a SoccerPlayers class to store data about players.
async function saveNewPlayer() {
const soccerPlayers = new Parse.Object("SoccerPlayers");
soccerPlayers.set("playerName", "A. Wed");
soccerPlayers.set("yearOfBirth", 1997);
soccerPlayers.set("emailContact", "[email protected]");
soccerPlayers.set("attributes", ["fast", "good conditioning"]);
try {
const result = await soccerPlayers.save();
console.log('New object created with objectId: ' + result.id);
} catch (error) {
console.error('Error: ' + error.message);
}
}After running this code, you can verify the new object in the Database section of the Back4app Dashboard. Note that you don’t need to manually create the SoccerPlayers class; it will be created automatically the first time an object is saved.

2 - Reading Parse Objects
To retrieve saved data, you can use a ParseQuery. For instance, to fetch the player created above by its objectId:
async function retrievePlayer() {
const query = new Parse.Query("SoccerPlayers");
try {
const player = await query.get("HMcTr9rD3s"); // Replace with the actual objectId
console.log("Player Name: " + player.get("playerName"));
console.log("Year of Birth: " + player.get("yearOfBirth"));
console.log("Email Contact: " + player.get("emailContact"));
} catch (error) {
console.error("Error retrieving object: " + error.message);
}
}In addition to objectId, you can also query by other parameters (e.g., yearOfBirth, playerName), offering greater flexibility in data searches.
3 - Updating Parse Objects
To update an object, retrieve it first, set new values for the desired attributes, and call the save() method.
async function updatePlayer() {
const query = new Parse.Query("SoccerPlayers");
try {
const player = await query.get("HMcTr9rD3s"); // Replace with the actual objectId
player.set("yearOfBirth", 1998);
await player.save();
console.log("Object updated successfully!");
} catch (error) {
console.error("Error updating object: " + error.message);
}
}4 - Deleting Parse Objects
To delete an object, retrieve it by objectId and use the destroy() method.
async function deletePlayer() {
const query = new Parse.Query("SoccerPlayers");
try {
const player = await query.get("HMcTr9rD3s"); // Replace with the actual objectId
await player.destroy();
console.log("Object deleted successfully!");
} catch (error) {
console.error("Error deleting object: " + error.message);
}
}Again, you don’t have to retrieve the object by its objectId. Parse has many search alternatives to retrieve information from ParseObjects, which you can find out more about in the official Parse documentation for each distinct technology.
Best Practices and Additional Tips
- Naming Conventions: Use ClassNamesLikeThis for classes and keyNamesLikeThis for keys to keep your code organized and readable.
- Common Error Checks: If you experience issues connecting to the Parse SDK, verify your SDK installation and configuration.
- Automatic Fields: Remember that each Parse object automatically includes createdAt, updatedAt, and objectId fields.
Next Steps
After persisting save and reading your first data on Back4app, we recommend keeping exploring the data storage using the guides below. You will find how to store supported data types, save and query relational data, use geopoints, and create optimized data models.
Conclusion
This guide provides a solid starting point for working with data on Back4app, making data storage and manipulation across platforms easy using the Parse SDK. For any questions, feel free to reach out to Back4app support!