Hello, I have a table in moralis server with columns “flip”, “bet”, “userName”, “totalAmount”, "
createdAt". Now, I want to get the live results(basically only 2 rows(results) satisfying conditions in query) for users who has names as “x”, “y” and bet amount equal to 100 for each and latest values for this conditions. i.e user “x” has bet amount 100 and its just 10 secs ago. same for “y”. So, I created table in frontend to show only this two users latest details with those conditions using useMoralisQuery shown below.
const { data , isFetching } = useMoralisQuery(
"MyGame",
(query) => {
query
.equalTo("bet", 100)
.distinct("userName")
.descending("createdAt")
.limit(2) // need only x & y users for now
.then(function(results) {
// my logic
})
.catch(function(error) {
console.log("error =", error)
})
return query
}
,
[],
{
live: true,
// onLiveEnter: (entity, all) => [...all, entity],
onLiveCreate: (entity, all) => [entity, ...all],
onLiveDelete: (entity, all) => all.filter((e) => e.id !== entity.id),
// onLiveLeave: (entity, all) => all.filter((e) => e.id !== entity.id),
onLiveUpdate: (entity, all) =>
all.map((e) => (e.id === entity.id ? entity : e)),
}
);
Im getting this error:
Unhandled Rejection (Error): You need to call Parse.initialize before using Parse
What am I doing wrong? How to change above query to get result for only “x”, “y” users for entries for bet=100 and latest values of both with that conditions from table?
I could not find any working examples in documents wrt react hook with distinct query. Please help me resolve this. Any links or working examples for distinct in react would be helpful.
Thanks in advance.