Calculating The Number Of Post Likes

i try to get likes count and if the user like the post or not
by server code but it give me error

400 - Cannot read property ‘objectId’ of undefined

here my code

async function loadPosts(currentUserId, whereClause) {
const postsStore = Backendless.Data.of(‘Posts’)
const usersStore = Backendless.Data.of(‘Users’)

const ITEMS_PER_PAGE = 10

const queryWithLikes = Backendless.Data.QueryBuilder.create()
‘Count(likes) as totalLikesCount’,
.setSortBy(‘created desc’)

if (whereClause) {

const posts = await postsStore.find(queryWithLikes)

if (!posts.length) {
return []

const ownerIds = []
const possibleLikedPostsIds = []

posts.forEach(post => {
if (!ownerIds.includes(post.ownerId)) {

post.liked = !!currentUserId && post.likes.some(like => like.objectId === currentUserId)

if (!post.liked && post.totalLikesCount > post.likes.length && currentUserId) {

if (possibleLikedPostsIds.length) {
const likedPostsQuery = Backendless.Data.QueryBuilder.create()
.setWhereClause(objectId in (${ => ’${d}’).join(',')}) and likes.objectId = '${currentUserId}')

const likedPosts = await postsStore.find(likedPostsQuery)
const likedPostsIds = => o.objectId)

posts.forEach(post => {
post.liked = post.liked || likedPostsIds.includes(post.objectId)

const publishersQuery = Backendless.Data.QueryBuilder.create()
.setWhereClause(objectId in (${ => ’${d}’).join(',')}))

const publishers = await usersStore.find(publishersQuery)
const publishersMap = publishers.reduce((m, user) => ({ …m, [user.objectId]: user }), {})

return => {
const publisher = publishersMap[post.ownerId]

return {
userId : publisher.objectId,
objectId : post.objectId,
image :post.image,
created : post.created,
content : post.content,
totalLikesCount: post.totalLikesCount,
liked : post.liked,
user : {
objectId: publisher.objectId,
avatar :publisher.avatar,
display :publisher.display,
name :,

****thanks for help

code photo

Could you please provide the minimalistic code example (or REST request) which reproduce the error with Backendless.

Hello @horus_art

Seems like you shared code of our Insta Clone Blueprint (template) Application, and as far as I know that code worked properly.

400 - Cannot read property ‘objectId’ of undefined

this error says that in code you are going to get a value objectId of undefined, I can recommend you to check the BusinessLogic log, there should be information about the problem line.

Regards, Vlad

1 Like

“code”: 0,
“message”: “Cannot read property ‘objectId’ of undefined”,
“errorData”: {}

i try to get posts with likes number and liked or not by the current user

by javascript server code like explanied here but give me this error

12:09:04 | SERVER_CODE | ERROR | [28872] TypeError: Cannot read property ‘objectId’ of undefined at /opt/backendless/repo/c1f71f56-eab6-a887-ff6e-07923eb3fd00/files/servercode/JS/default/PRODUCTION/services/posts.js:177:33 at () at loadPosts (/opt/backendless/repo/c1f71f56-eab6-a887-ff6e-07923eb3fd00/files/servercode/JS/default/PRODUCTION/services/posts.js:173:15) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Object.executor.execute (/usr/local/lib/node_modules/backendless-coderunner/lib/server-code/runners/tasks/executor.js:191:16) at async executeTask (/usr/local/lib/node_modules/backendless-coderunner/lib/server-code/runners/cloud-worker.js:55:24) at async processTask (/usr/local/lib/node_modules/backendless-coderunner/lib/server-code/runners/cloud-worker.js:83:3)

take a look at this line


the problem is in this query but i do not know whats absolutly couse thate error

I’m not sure about the issue in the code, because there is no getting the objectId property

try to add the following code to 168 line

console.log('publisher', publisher)

sorry ,
but i am new to backendless
where this shoud print publisher (where is the console )

you can see that log messages in the RealTimeLogging

[Exception: TypeError: ‘caller’, ‘callee’, and ‘arguments’ properties may not be accessed on strict mode functions or the arguments objects for calls to them at Arguments.r (:1:83)]

where does the error come from?

no thing printed

where can you this error: ?

[Exception: TypeError: ‘caller’, ‘callee’, and ‘arguments’ properties may not be accessed on strict mode functions or the arguments objects for calls to them at Arguments.r (:1:83)]

when press in this (arguments) i get this error

could you please share a code snippet where you added the console.log line