Read and Write data
In this guide, you will learn how to create, read, update and delete Data Objects on Back4App using the Parse SDK. Storing data on Back4App is built around Parse. Object class. Each Parse.Object contains key-value pairs of JSON-compatible data. This data is schemaless, which means that you don’t need to specify ahead of time what keys exist on each Parse.Object.
You can also specify the datatypes according to your application needs and persist types such as number, boolean, string, DateTime, Array, GeoPointers, and Object, encoding them to JSON before saving. Parse also supports store and query relational data by using the types Pointers and Relations.
- To create, read, update and delete Parse Objects at Back4App.
To complete this tutorial, you will need:
An app created at Back4App.
º Follow the Create a new App tutorial to learn how to create an app at Back4App.
Install Parse SDK
° Follow the Connect to Back4App tutorial to learn how to install Parse SDK to your application.
To store data in the Back4App database from the frontend side, you have to use ParseObjects. Each ParseObject has to be associated with a class, so you will be able to distinguish different sorts of data.
For example, imagine that your application is related to soccer and you want to store data about soccer players around the world, such as their names, years of birth, email contacts, attributes, etc.
We recommend that you NameYourClassesLikeThis and nameYourKeysLikeThis, just to keep your code looking pretty.
A ParseObject is created extending your new SoccerPlayer class and then defining each class attribute using the set method. The save method will create the class on Back4App and store your objects using the datatypes you defined. Below you can find other code samples for other Parse SDKs.
Isn’t Parse SDK working properly? Make sure you have installed it correctly by checking the complete Install Parse SDK guide projects. Links below.
JavaScript - Android - Arduino - iOS Swift - iOS Objective-C - .NET - Unity - PHP - REST API
After running the code above, you will probably be wondering if anything happened. To make sure data was saved, check out these steps:
1. Go to Back4App website, log in, click on My Apps section, find your app, and click on DASHBOARD.
2. Then, click on the Core button. The Core section of your application’s Dashboard contains the database that Back4App provides to you. Here you should see that a class named SoccerPlayers has been created and has stored one object with all the information of the “A. Wed” soccer player, as you required.
Note that you didn’t have to set up a class called “SoccerPlayers” on Back4App before running this code, the ParseObject declaration created it for you. Also, theParse Object you specified defined the datatypes for each column. You can also find the automatic fields created by Parse: createtAt, updatedAt, and objectId.
The code sample won’t work as expected if you haven’t installed Parse SDK correctly for the technology of your project.
You will now read the object that you saved. Start copying objectId on the Dashboard. You will retrieve the object using a ParseQuery. After querying the object you must access the object properties using the get method for each data type.
Isn’t Parse SDK working properly? Make sure you have installed it correctly by checking the complete Install Parse SDK guide projects. Links below.
JavaScript - Android - Arduino - iOS Swift - iOS Objective-C - .NET - Unity - PHP - REST API
Now you may be wondering if every time you want to read data from a ParseObject you will have to knowits objectId. The answer to this question is: NO! To search for an object, you can use many other search alternatives, such as searching in “SoccerPlayers” class for a player with a specific name, or for players who were born in a certain year, etc. Parse has many search alternatives to find ParseObjects, which you can find out more about in our guides or on the official Parse documentation related to ParseQueries. You can find the corresponding links below.
Find out more information about queries for ParseObjects in the links below:
The code sample won’t work as expected if you haven’t installed Parse SDK correctly for the technology of your project.
To update a ParseObject, you just need to retrieve the object using the objectId, then define which new values you want for each attribute. and then call the save() method. Let’s update the SoccerPlayer object we’ve created.
Isn’t Parse SDK working properly? Make sure you have installed it correctly by checking the complete Install Parse SDK guide projects. Links below.
JavaScript - Android - Arduino - iOS Swift - iOS Objective-C - .NET - Unity - PHP - REST API
The code below won’t work as expected if you haven’t installed Parse SDK correctly for the technology of your project. To verify if you have done it correctly, go to Add Back4App to your App project tutorial to ensure followed the steps as required.
To delete a ParseObject, just set its objectId and then call the destroy() method.
Isn’t Parse SDK working properly? Make sure you have installed it correctly by checking the complete Install Parse SDK guide projects. Links below.
JavaScript - Android - Arduino - iOS Swift - iOS Objective-C - .NET - Unity - PHP - REST API
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.
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.
At this point, you have learned how to CRUD (Create, Read, Update, and Delete) Objects using Parse SDK. In case you face any trouble while deploying your code, please contact our team via chat!