Dattatray
Dattatray

Reputation: 1873

Scan operation with FilterExpression having multiple conditions with "and" operator

I am writing a lambda function in Go and using DynamoDB as my database.

I need to write a scan operation with multiple conditions (e.g. field1 = value1 and field2 = value2 and field3 = value3).

I am creating a FilterExpression string based on how many parameters/conditions are supplied by the user.

My filter expression is as below:

(#field1 = :field1Val) and (#field2 = :field2Val)

I am also providing the ExpressionAttributeNames and the ExpressionAttributeValues in the maps to the scan operation input. However, I am not getting any results (count = 0).

If I specify only one condition or if I use "or" operator instead of "and" operator, I get the results.

Looks like the second condition (#field2 = :field2Val), even if I use any field ( field3, field4, etc.) is always resulting in "false".

Any pointers?

Where do I see the logs of this query/scan operation?

Upvotes: 1

Views: 1244

Answers (1)

Dattatray
Dattatray

Reputation: 1873

I got the problem.

The filter condition string is correct -

(#field1 = :field1Val) and (#field2 = :field2Val)

I was iterating in a loop to find out which search parameters are specified by the user.

There was a mistake in the code, I was using the same variable name for all the attribute names.

attributeName := "field1"
attributeNamemap["#field1"] = &attributeName

This "attributeName" field was used for all the search parameters. This was causing the problem, I used different variables and it started working.

Upvotes: 0

Related Questions