0

I am currently using mongodb and plan to migrate to dynamodb. I have a pretty complex algorithm to find elements implying AND and OR.

Here is an (simplified) example. Search engine through users. Let's imagine user has 2 fields: lastName and firstName.

A user search "Harry Po"

The search engine should search:

$or : [{$and : [{lastName : "harry"}, {firstName: "po"}]}, {$and : [{lastName : "Po"}, {firstName: "harry"}]}]

And we can imagine other stuff like having lastname "harry po" and no firstname etc

With mongoDB I am using java wrapper Spring DataMongoDB which allowed me to do pretty all the stuff I wanted to do. However I am not able to find a way to do it with dynamodb

I found this page https://stackoverflow.com/questions/24275243/writing-dynamodb-or-condition-query#=

Howver it looks like I can only do an OR between my conditions. Is there something I am missing?

Stennie
  • 63,885
  • 14
  • 149
  • 175
Geoffrey
  • 1,151
  • 3
  • 13
  • 26

1 Answers1

0

In DynamoDB you can specify scan condition that can contain AND and OR operators that combine expressions with operators like: >=, =, <, etc.

Here is what DynamoDB docs is saying about it:

ComparisonOperator - A comparator for evaluating attributes. For example, equals, greater than, less than, etc. The following comparison operators are available: EQ | NE | LE | LT | GE | GT | NOT_NULL | NULL | CONTAINS | NOT_CONTAINS | BEGINS_WITH | IN | BETWEEN

You can use a ConditionalOperator to combine ComparisonOpertors:

A logical operator to apply to the conditions in a Expected, QueryFilter or ScanFilter map:

AND - If all of the conditions evaluate to true, then the entire map evaluates to true.

OR - If at least one of the conditions evaluate to true, then the entire map evaluates to true.

If you omit ConditionalOperator, then AND is the default.

Ivan Mushketyk
  • 8,107
  • 7
  • 50
  • 67