equalTo not working for some queries in Cloud functions

equalTo doesn’t seem to be working when referring to pointers. i either get no items or all the table items for iQuery and cQuery

Moralis.Cloud.define("getAuctionsBidsItems", async (request) => {
  const logger = Moralis.Cloud.getLogger();
  
  const iQuery = new Moralis.Query("ItemsForAuction");
  iQuery.equalTo("user.objectId",request.params.objectId);
  iQuery.select("auctionEndTime","uid","tokenId","floorPrice","user.id","highestBid","closed");
  let iResults = await iQuery.find({useMasterKey:true});
  logger.info('i Results '+iResults);
  
  const bQuery = new Moralis.Query("AuctionItemBids");
  bQuery.equalTo("buyer",request.params.address);
  bQuery.select("uid","bid","auctionItem.auctionEndTime","closed");
  let bResults = await bQuery.find({useMasterKey:true});
  logger.info('b Results '+bResults);
  
  const cQuery = new Moralis.Query("ItemsForSale");
  cQuery.equalTo("user.id",request.params.objectId);
  cQuery.select("uid","askingPrice","tokenId","address","token.name","isSold","user.ethAddress");
  let cResults = await cQuery.find({useMasterKey:true});
  logger.info('c Results '+request.user.attributes.id);

  return iResults.concat(bResults.concat(cResults));
});

Calling function using hard coded id since user.get(‘id’) seems to be undefined.

const loadHistory = async () => {
    try {
      //get users auctions and bids
      user = await Moralis.User.current();
      let params = { objectId: "CHlaUtKkDQUS9UaYcYIOSusJ", address: user.get('ethAddress') };
      
      Moralis.Cloud.run("getAuctionsBidsItems", params).then((res) => {
        console.log("res : ", res);
        setHistoryView(renderHistory(res));
      });


    } catch (error) {
      console.log("err: ", error);
    }
  }

ItemsForSale


ItemsForAuction

AuctionItemBids

1 Like

Hey @PeacanDuck

I don’t understand why do you use in this case iQuery.equalTo("user.objectId",request.params.objectId); instead of iQuery.equalTo("objectId",request.params.objectId);

Could you explain please :man_mechanic:

Hey thought that is how you reference a pointer since that’s how i have it working in my select in bQuery

bQuery.select(“uid”,“bid”,“auctionItem.auctionEndTime”,“closed”);

since objectId is on the user table and i have a coloumn called user with a pointer of a user

looks like i needed to use aggregate with match

1 Like