如何在Backendless.com中增加字段

时间:2016-06-23 06:54:30

标签: javascript backendless mbaas

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

目标:所有用户都可以查看彼此的帖子。现在,当用户喜欢某人发帖时,那个帖子就像theCounter应该增加1。

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

1)检索帖子

2)做LikeCount ++

3)保存帖子

正如您所看到的,存在数据持久性问题。如果你能告诉我一个可行的代码,请帮助它。虽然我找到了This like,但我无法弄清楚如何实现它

1 个答案:

答案 0 :(得分: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