#Custom query not filtering data

5 messages · Page 1 of 1 (latest)

winter chasm
#
{
      path: "/me",
      method: "get",
      handler: async (req, res, next) => {

        if (!req?.user?.id) {
          return res.status(404).send({ error: "user not found" });
        }

        console.log(req.user.id)

        const query = {
          "owner.id":   req.user.id, 
        };

        const data = await payload.find({
          depth : 2,
          collection: "thoughts",
          where : {
            "owner.id":   req.user.id, 
          }
        });

        
        if (data) {
          console.log(data)
          res.status(200).send( data );
        } else {
          res.status(404).send({ error: "not found" });
        }
      },
    },
chilly owlBOT
sinful sand
#

Hey @winter chasm! Try adjusting your query to the following:

const data = await payload.find({
  depth : 2,
  collection: "thoughts",
  where : {
    owner: {
      equals: req.user.id
    }
  }
});

Here is the section in the docs that talks about querying: https://payloadcms.com/docs/queries/overview

winter chasm
winter chasm