Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
Can't query by ID as second parameter with AWS DataStore

I am total noob to AWS, DataStore, and DynamoDB. I can't figure out why this isn't working.

If I attempt query an object related to my users ID from Cognito this seems to work. If I console log I get an array with one User.

    let profile = await DataStore.query(User, (u) =>
      u.id('eq', user.attributes.sub)
    );

    // Returns [Model]
    console.log('[LOADING USER DATA]', profile);

If I attempt query an object related to my users ID like this. (as recommended by the docs). I get undefined.

    let profile = await DataStore.query(User, user.attributes.sub);

    // Returns undefined
    console.log('[LOADING USER DATA]', profile);

Dynamo Data looks fine to me but am I using the wrong primary key ID field or something?

{
 "id": "929e6e62-e3a0-4b84-b050-72c53eebda93",
 "_lastChangedAt": 1644433699,
 "status": "Active",
 "createdAt": "2022-02-09T19:08:18.548Z",
 "name": "Test",
 "orgs": [
  "b6508155-f5cf-49b7-88d6-0e605677c4e4"
 ],
 "_version": 1,
 "role": "User",
 "updatedAt": "2022-02-09T19:08:18.548Z",
 "orgID": "b6508155-f5cf-49b7-88d6-0e605677c4e4",
 "title": ""
}

What am I doing wrong?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!