0

Bellow是我拥有的表结构的概述

    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

目的:所有用户都可以查看彼此的帖子。现在,当用户喜欢某人的帖子时,该帖子的 likeCounter 应该增加 1。

问题:我找不到更新likeCounter 的持久方法。唯一有效的方法是

1) 检索帖子

2)做likeCount++

3) 保存帖子

如您所见,存在数据持久性问题。如果您能向我展示一个可行的代码,请帮助它会更好。虽然我发现了这个,但我不知道如何实现它

4

1 回答 1

0

查看 Backendless Atomic Counters API。

这是伪代码:

    //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 );

所有场景都在文档中描述:https ://backendless.com/documentation/utilities/js/ut_atomic_counters_api_js.htm 。

于 2016-06-29T13:11:48.427 回答