0

I'm trying to use SQL IN clause kind of feature in dynamoDB. I tried using withFilterExpression but I'm not sure how to do it. I looked at similar questions as they were too old. Is there a better method to do this? This is the segment of code I have got. I have used a static List as example but it is actually dynamic.

def getQuestionItems(conceptCode : String) = {

  val qIds = List("1","2","3")

  val querySpec = new QuerySpec()
  .withKeyConditionExpression("concept_id = :c_id")
  .withFilterExpression("question_id in :qIds") // obviously wrong
  .withValueMap(new ValueMap()
    .withString(":c_id", conceptCode));
 questionsTable.query(querySpec);
}

I need to pass qID list to fetch results similar to IN clause in SQL Query.

Maniyan
  • 35
  • 4

1 Answers1

1

Please refer to this answer. Basically you need to form key list/value list dynamically

.withFilterExpression("question_id in (:qId1, :qId2, ... , :qIdN)")
.withValueMap(new ValueMap()
    .withString(":qId1", ..) // just do this for each element in the list in a loop programmatically
    ....
    .withString(":qIdN", ..)
);

Mind there is a restriction on maxItems in 'IN'

Anton
  • 1,432
  • 13
  • 17