title: How do I query DynamoDB with non primary key field?
body: <p>I have the following data in my dynamoDB table.</p>
  
  <p><a href="https://i.stack.imgur.com/ksPB0.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ksPB0.png" alt="enter image description here"></a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>const userStatusParams = {
          TableName: process.env.USERSTATUS_TABLE,
          KeyConditionExpression: "loggedIn = :loggedIn",
          ExpressionAttributeValues: {
            ":loggedIn": true
          }
        };
        var usersResult;
        try {
          usersResult = await dynamoDbLib.call("query", userStatusParams);
          console.log(usersResult);
        }catch (e) {
          console.log("Error occurred querying for users belong to group.");
          console.log(e);
        }
  </code></pre>
  
  <p>Amazon returns back this error:</p>
  
  <pre><code>{ ValidationException: Query condition missed key schema element: userId
      at Request.extractError ...
  </code></pre>
  
  <p><strong>How do I have it return all records where loggedIn == true?</strong></p>
  
  <p>My database is currently structured like this via my serverless.yml config.</p>
  
  <pre><code>phoneNumberTable: #This table is used to track phone numbers used in the system.
        Type: AWS::DynamoDB::Table
        Properties:
          TableName: ${self:custom.phoneNumberTable}
          AttributeDefinitions: #UserID in this case will be created once and constantly updated as it changes with status regarding the user.
            - AttributeName: phoneNumber
              AttributeType: S
          KeySchema:
            - AttributeName: phoneNumber
              KeyType: HASH
          ProvisionedThroughput:
              ReadCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.pstage}}
              WriteCapacityUnits: ${self:custom.dynamoDbCapacityUnits.${self:custom.pstage}}
  </code></pre>
  
  <p>I did a little research into this via other answers but could not figure out for my situation.  In other answers they had sort keys but I do not use a sort key here.</p>