Hi,
I hope you will be able to help me, as I haven’t found much related to it in the documentation.
I am trying to create an atomic counter in the data table and be able to increate it from the js cloud code, in afterTransaction block. Can you please give a hint at least how can I make it, as the only one I can find is just an integer and I don’t know how to use is with Backendless.Counters.getAndIncrement for example.
atomic counters are not stored in the table. You can see them in the Counters section under the Data section, but if I understand you correctly, you want to create a column in a regular table and store that value there - you can’t do that because it won’t be atomic anymore. Under the hood, we use redis for atomic counters.
If I misunderstood you, please clarify the question, I will try to answer it.
Basically, I need to create a counter per user, to count how many posts user had. From what I’ve understood those counter are global, so one per all the users. Is it possible to make them per user somehow?
I think in your specific case you don’t need to use atomic counters. You can just use a regular table column with INT type and store this value there. Also if you store user posts as relations of a user object, or if each post has a user id in some column, you can use our Aggregate API where the Count function is available and very suitable for this case.
The problem is that I have to count all posted posts, even if they were previously deleted, so COUNT does not work for me, unfortunately. So the only way, I believe, is to retrieve an object, increment one field and update it. Okay, thanks a lot!
Btw, when something is deleted, you do not need to remove it from the database. Another approach is to have a column such as isDeleted and set it to true. This way you can retrieve data that is not deleted and use the count function as it is meant to be.