0

Bellow is the overview of the table structure i have

    Table data
----------------------------------
-             User               -
----------------------------------
| objectId |   name   | password |
----------------------------------
| z12ttttt | Matt     | hidden   |
| z12zzzzz | Jobs     | hidden   |
| z12bbbbb | Ballu    | hidden   |
| z12aaaaa | Stephin  | hidden   |
----------------------------------

--------------------------------------------------
-                       Post                     -
--------------------------------------------------
| objectId |   post    |  postBy  | likesCounter |
--------------------------------------------------
| blabla   | Head Pain | z12ttttt |      0       |
| blab12   | Back Pain | z12ttttt |      0       |
| blab23   | Sleepy    | z12ttttt |      0       |
| blab90   | Head Pain | z12zzzzz |      0       |
| blab90   | lets Dance| z12bbbbb |      0       |
| blab90   | lets jump | z12aaaaa |      0       |
--------------------------------------------------
//postBy has a 1 to 1 relationship with User table

Aim : All the users can view each others posts. Now when ever a user likes someones post, that post's likeCounter should increase by 1.

Problem : I cannot find a persistent way to update the likeCounter. The only way which is working is to

1) Retrieve Post

2) Do likeCount++

3) Save Post

As you can see there is a data persistency issue. Please help it will be better if you could show me a workable code. Although i have found This like but i cant figure out how to implement it

Tabby
  • 388
  • 1
  • 11

1 Answers1

0

Look at Backendless Atomic Counters API.

Here is pseudocode:

    //Create counter for every user by it`s objectId.
    var objectId = Post.getObjectId();
    // get counter manager
    var counter = Backendless.Counters.of( counterName );
    // increment or decrement
    counter.incrementAndGet( async );

All scenarios are described in documentaion: https://backendless.com/documentation/utilities/js/ut_atomic_counters_api_js.htm.

schaffe
  • 399
  • 2
  • 16
  • Thank You!! But i need to know how to use it. This link i have mentioned in my question above. – Tabby Jul 06 '16 at 14:22