Guide to increasing a field value in Backendless.com

Below is an 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 users can view each other's posts. Now, whenever a user likes someone's post, that post's likeCounter should increase by 1.

Problem: I am unable to find a persistent way to update the likeCounter. The only method that is working is:

1) Retrieve Post

2) Increment likeCounter++

3) Save Post

As you can see, there is a data persistency issue. Please help. It would be better if you could provide me with some workable code. Although I have come across this resource, I am having difficulty implementing it.

Answer №1

Check out the Backendless Atomic Counters API for managing counters.

Here is an example in pseudocode:

//Create a counter for each user using their objectId.
var objectId = Post.getObjectId();
// Get the counter manager
var counter = Backendless.Counters.of( counterName );
// Increment or decrement the counter
counter.incrementAndGet( async );

You can find detailed information on all scenarios in the documentation: .

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble getting gulp set up and running with npm?

I am currently in the process of setting up gulp using npm in order to execute my project. Based on my understanding, all I need to do is enter "npm install gulp" in the command line at the location of my project like this : https://i.stack.imgur.com/hPU ...

A promise is given when a value triggers a function

Having a problem with my code in the second function. When I log inside the function, it works fine. But when I assign a variable and call the function, it returns a pending promise instead of true or false. const mongoose = require('mongoose') c ...

Retrieving Information from Website Components in JavaFX Web View

I am currently developing a Java FX program that loads a folder containing HTML/CSS/JS files with 3 different websites. While the websites are displaying correctly in the webview, I am looking for a way to capture user interactions, such as checkbox selec ...

What is the best way to ensure an AJAX get-request waits for the page to finish rendering before providing a response?

I've been working on a Greasemonkey Script for a specific section of this website (Site1). Site1 offers various deals and discounts, and my script is designed to perform the following task: When a user visits an offer on Site1, the script checks with ...

What is the best way to populate a div with multiple other div elements?

My current project involves creating a sketchpad using jQuery for an Odin Project assignment. However, I have encountered an issue with filling the canvas (wrapper div) with pixels (pixel divs). The canvas does not populate correctly. Here is the link to m ...

Unable to update to the most recent version of React-Bootstrap

I'm facing an issue while trying to upgrade to the newest version of react-bootstrap. When I run: npm install --save react-bootstrap The following message appears: npm notice created a lockfile as package-lock.json. You should commit this file. npm ...

Can sweetalert2 be used as a tooltip?

I have a query, is it feasible to include a tooltip in the alert message? Alternatively, could there be another tooltip option available? Swal.fire({ title: '<strong>An example with HTML tags</strong>', icon: 'info', ...

What is the JavaScript method for updating an HTML5 datalist to show new options?

When populating options dynamically into an HTML5 datalist, I'm facing an issue where the browser tries to display the datalist before all the options have loaded. As a result, the list either does not show up completely or only partially shows up. Is ...

Tips for arranging information in ng-repeat using nested objects within JSON data on AngularJS

Looking to display an array of object properties in an Angular view. Here is the object: $scope._Json = { "foo": { "ItemDimension1": { "Item": "item1", "ItemIndex": 1, "SelectedItems": [{ "C ...

By using .innerHTML to create an element, the validation of HTML form fields can be circumvented

After inserting a form field with standard HTML validation constraints (pattern & required), using the .innerHTML property does not trigger validation. While I understand the difference between creating an element with .innerHTML and document.createElement ...

How can you eliminate a specific element from an HTML document?

Utilizing localStorage can be tricky when it comes to keeping the JSON file hidden from being displayed on the HTML page. One approach I used involves sending the JSON file to the client once and then performing all logic using that file. To prevent the JS ...

Explore the steps for setting up automatic reconnection in socket.io

When establishing a socket.io connection, I use the following code: var socket = new io.connect('http://localhost:8181', { 'reconnect': true, 'reconnection delay': 500, 'max reconnection attempts': 50 }) ...

Experimenting with the static method within a singleton class using Typescript and Sinon

I have a separate layer in my application that uses a DAO class to retrieve data from the repository. I've implemented the DAO class as a Singleton and made its methods static. In another class, I've created service methods to manipulate the dat ...

Security Error when using the JavaScript map function in FireFox

My current dilemma involves using a JavaScript code to extract the above-the-fold CSS from my websites. Surprisingly, it functions flawlessly on Google Chrome. However, when I attempt to execute it on Firefox, an infamous 'SecurityError' occurs: ...

Tips for utilizing the getServerSideProps function

I want to improve the SEO friendliness of my page by utilizing the getServerSideProps method. Despite searching online, I couldn't find a specific example that fits my situation. I am uncertain about how to proceed since I currently have a useEffect m ...

Stop users from refreshing or closing the window while an axios request is being processed

I'm in the process of creating a dynamic Web Application that involves utilizing Axios.get requests. Given that Axios operates asynchronously, my approach includes an async function along with await axios.all: async handleSubmit(){ const ...

Vue3 - Implementing a seamless communication channel between two child components

Vue 3 has brought about changes in my component structure, as shown below: In this setup, ChildA can communicate with ChildB and requires ChildB to update its state accordingly. In Vue 2, I could send an event from ChildA: this.$root.$emit('new-mess ...

Tips on how to remove the filter from a select element using Angular?

My code includes the following HTML: <select ng-options="mark.id as mark.name for mark in marks" ng-model="markSearch.mark.id"> <option value="">-- Choose mark --</option> </select> ... <tr ng-repeat-start="pipeType in pipeT ...

Please explain this ES6 syntax to me: Using a colon after a function call

While exploring the documentation for a flux store in React, I came across an example that caught my attention. import {ReduceStore} from 'flux/utils'; class CounterStore extends ReduceStore<number> { getInitialState(): number { ret ...

Tips for using the deferred method in ajax to enhance the efficiency of data loading from a php script

I recently discovered this method of fetching data simultaneously using ajax. However, I'm struggling to grasp the concept. Can someone please explain how to retrieve this data from a PHP script and then add it to a div similar to the example provided ...