Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Custom query not filtering data

default discord avatar
aaronksaunderslast year
2
{
      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" });
        }
      },
    },
  • Hey

    @923397761045512202

    ! 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
  • default discord avatar
    aaronksaunderslast year

    Thanks, I figured it out late last night after trial and error, and I did read this documentation but there is no specific example on relationships. I was checking against owner.id and not owner 🙏🏾



    I like what I see with payload, a little worried about running into things like this when working on a client project… trying to come up with all with a robust example project to get all of the questions answered so we are not blocked when we are on the clock. Thanks for your help

    @281120856527077378
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.