Parse Server Database Comprehension

58 Views Asked by At

I have no experience with ParseServer, and I have a frustrated question about a few things. First is the way to update an object. Ok here we go, this is the process to create an object:

Creating Objects:

ParseObject gameScore = ParseObject.create("GameScore");
gameScore.put("score", 1337);
gameScore.put("playerName", "Sean Plott");
gameScore.put("cheatMode", false);
gameScore.save();

and then after saving I can get the Id by:

String objectId = gameScore.getObjectId();

The problem is where to store objects Ids once I want to access it later? Because I can't use local variables to store object Ids otherwise it wouldn't make sense since storage is up to the Database also variables values get reseted after rebooting.

Another problem:

Updating Objects:

// Assuming ParseObject 'gameScore' with key 'score'  already exists.

    gameScore.put("score", 73453);
    gameScore.save();

Well seems I can only update an object by another object, but the local object from my side will be reseted every time my App is restarted so my App won't be able to retrieve it again in case either in need to update it or fetching by Id.

I mean what is the point of putting Ids into local objects/variables which will be reseted when the App is restarted? I mean it would make sense for me if I could update an object by an storaged Id instead of another object/variable.

Much appreciate if someone help me to understand and clarify these questions.

1

There are 1 best solutions below

0
On BEST ANSWER

You need to use queries to fetch objects as needed e.g. this is old code I wrote to query the parse database:

ParseQuery<ParseAttendance> pq = ParseQuery.getQuery(ParseAttendance.class);
pq.setLimit(1000);
pq.setSkip((page - 1) * pq.getLimit());
pq.whereEqualTo("studentId", studentId);
pq.orderByDescending("year");
pq.addDescendingOrder("month");
pq.addDescendingOrder("day");
List<ParseAttendance> lst = pq.find();

You don't save object instances you query based on what you are looking for. In this case it returns a java.util.List of attendance objects.