2

I'm trying to query for two different values from the same field or column. In this instance I would like to retrieve rows where the fulfilled item are true or false. Below is an example of what I'm trying to do.

const params = {
            TableName: "Orders",
            IndexName: 'fulfilled-shippingId-index',

            KeyConditionExpression: "fulfilled = :fulfilled",
           //FilterExpression : 'contains(fulfilled=true) OR fulfilled=false',
            ExpressionAttributeValues: {
              ":fulfilled": "true",
              ":fulfilled": "false"
            }

let me know if this isn't possible or if there would be a different way to do this through a loop or maybe just multiple requests from the application? As of now it just returns the last Expression Attribute Value.

thanks!

user1721061
  • 21
  • 1
  • 3
  • Hmm can you not use "IN" within a FilterExpression, I'm afk at the moment I'll update in a bit? – Mrk Fldig Mar 18 '18 at 10:20
  • Thank you, Mrk, it seems there is an IN within filter expression but It doesnt seem to be working for me either. FilterExpression : "fulfilled IN (:false, :true)", ExpressionAttributeValues: { ":false": "false", ":true": "true" }, – user1721061 Mar 19 '18 at 01:55
  • Possible duplicate of [how to use in operator in dynamo db](https://stackoverflow.com/questions/40222158/how-to-use-in-operator-in-dynamo-db) – Alex Clement Jul 18 '19 at 20:34

1 Answers1

-1

Unfortunately, this isn't possible.

KeyConditionExpression

The condition must perform an equality test on a single partition key value.

You must specify a single partition key value.

Using a FilterExpression here won't help since FilterExpressions are applied after the data is read. Also, a FilterExpression cannot contain partition key or sort key attributes.

Since fulfilled = true OR fulfilled = false is a tautology, I would recommend just using Scan to read all of the items in your fulfilled-shippingId-index

tleef
  • 3,516
  • 1
  • 24
  • 34