Query in backend jsw won't pass hasNext()

From a backend jsw file


export function queryProfiles() {
    return ("MembersProfile")
    .limit(10)
    .find()
    .then( (results) => {
        console.log(results.hasNext()); // returns true
        return results;
    });
}

In the frontend code

queryProfiles()
.then( (results) => {
    console.log(results.hasNext()); // returns undefined
});

I’m not sure why the results contains the hasNext() function in the backend, but it won’t pass it when called from the frontend. I’m loading a repeater.data with the results, so I have to create my own pagination element.

If I move the queryProfiles() function definition to frontend code it works fine. Not sure what’s going on technically.

Why is it not passing the hasNext(), hasPrev() functions to the frontend call of the function?

I’m guessing it’s because the web module is a proxy and the arguments and return values are serialized using JSON and passed that way. :confused:

You are not quite correctly returned the result from the backend function. See the article Returning in a .then( ) . You probably just need to add a return to your query statement, like this:

 return wixData.query("MembersProfile")

Sorry, the code above was pseudo-code, not the actual function. There is a return statement. I’ll amend my original question.

@winston I hope it’s still pseudo code, since the amended statement does nothing:

return("MembersProfile")

Please understand that pseudo code doesn’t help us figure out what’s wrong with your real code. You need to explain what you are trying to do, what works and what doesn’t. Also, share your real code (the “actual function”) so that we can see what you are doing and hopefully be able to help.

I confirm that if you use a backend function hasnext does not work.
If you put the query in the same page, it works perfectly.
Did you manage to solve the problem?

Here my example NOT working
backend
export function getrecord ( Owner ) {
return wixData . query ( ‘DBxxx’ ). eq ( ‘_owner’ , Owner )
. limit ( 10 )
. find ()
}

frontend
let list = await getrecord(Owner)
let hasNext = list . hasNext ();
let hasPrev = list . hasPrev ();

Here WORKING in frontend
let list =
await wixData . query ( 'DBxxx ). eq ( ‘_owner’ , Owner )
. limit ( 10 )
. find ()

**let**  hasNext  =  **await**  list . hasNext (); 
**let**  hasPrev  =  **await**  list . hasPrev ();