Database Query return null

Moralis.Cloud.afterSave(“CharacterNFTMinted” , async (request) =>{

const confirmed = request.object.get("confirmed");
const sender = request.object.get("sender");

const query = new Moralis.Query("Notifications");
const pipeline = [
{ match: { address: { $in: [ "sender" ]} } },
];

const result = await query.aggregate(pipeline,{ useMasterKey: true});     
const email     = result[0].email
const number    = result[0].number
const isEnabled = result[0].isEnabled
const address   = result[0].address

});

Can you help me with this? If I run this on the console of the dashboard returns the object but in moralis cloud returns null

you could add some logging to see what it is happening there, you can use logger.info

  • 2022-01-28T22:57:04.578Z - #24361495 :hourglass_flowing_sand: 0x6cf812103f908cc7d696109b6d0b2b9e1ea0484398469a69974f00eeb9e20975 Log
  • 2022-01-28T22:57:04.576Z - TypeError: Cannot read properties of undefined (reading ‘email’) at eval (eval at customUserPlugin (/moralis-server/cloud/main.js:156:21), :1:303) at processTicksAndRejections (node:internal/process/task_queues:96:5)
  • 2022-01-28T22:57:04.575Z - afterSave failed for CharacterNFTMinted for user undefined: Input: {“block_timestamp”:{"__type":“Date”,“iso”:“2022-01-28T22:57:03.000Z”},“transaction_hash”:“0x6cf812103f908cc7d696109b6d0b2b9e1ea0484398469a69974f00eeb9e20975”,“log_index”:70,“sender”:“0x930b237efe408ecfcad7c1e812bbec9589815356”,“tokenId”:“32”,“characterIndex”:“16”,“address”:“0x697034b51fb77c1061e4273d1027370bd30cf027”,“block_hash”:“0xb730d910d4948844bbf73da382fcd1afd95273b1ebece0198438d215d5605327”,“block_number”:24361495,“transaction_index”:12,“createdAt”:“2022-01-28T22:57:04.533Z”,“updatedAt”:“2022-01-28T22:57:04.533Z”,“objectId”:“DV8IV2ZS1kcqPFlEKE9bmoOO”} Error: {“message”:“Cannot read properties of undefined (reading ‘email’)”,“code”:141}
  • 2022-01-28T22:57:04.501Z - #24361495 :hourglass_flowing_sand: ERC721 Balance Pending: token_id: 32
  • 2022-01-28T22:57:04.148Z - #24361495 :hourglass_flowing_sand: 0x6cf812103f908cc7d696109b6d0b2b9e1ea0484398469a69974f00eeb9e20975 Log
  • 2022-01-28T22:56:39.534Z - #24361483 :hourglass_flowing_sand: Polygon Balance Pending: 499712346377689702
  • 2022-01-28T22:56:39.388Z - #24361483 :hourglass_flowing_sand: 0x922721bd044b6604deb33bf4bd5fb5aad61e9d21062ebcb7422d653414078ee1 0 Tx
  • 2022-01-28T22:56:25.024Z - Create new client: d102eeac-33ce-4a8d-8954-296d4d8b6ef0
  • 2022-01-28T22:56:23.892Z - Can not find subscription with clientId cf4f64b4-5946-424f-96fb-6337450c0eab subscriptionId 1

Basically what I’m trying is to read the Request object, so I can get wich addy is sending the request, and then to check if they have notifications enabled… to get the object to send the email or to the phone number, and see if they user has enabled the notifications.

that sender seems to be a string there and not a variable

So… I need to change “sender” to, sender?

how it would be the rigth way to do a query inside a cloud function sorry for bothering crypto kid but I was able to find that in the documentation but not how to do it inside a cloud fuction.

btw, any documentation on how to do it like this in the pipeline? way like mongo db or something is based of… to research…

you can try this: https://docs.mongodb.com/manual/reference/aggregation-variables/

Ok it seems to be working but I don’t get any log regarding the cloud function, is there any way to check what it is actually doing if it is receiving the correct data through the logs or run it arbitrarily and return something else?

did you try to use logger.info for example?

This one?

To use this… I need to setup a custom IDE so the webpack thing… can pack the dependecy to be used in the moralis cloud ins’t it?

Or how to use it inside the cloud fuction…

no, in cloud code you can add logging with that code: https://docs.moralis.io/moralis-server/cloud-code/cloud-functions#console.log