如何在Dynamodb中使用具有多个条件的FilterExpression

Jit*_*hPS 12 amazon-dynamodb boto3

我想在dynamodb上做表扫描下面是javascript中的代码

var params = {
    TableName: 'Contacts',
    FilterExpression: 'begins_with(CustomerName,:value)OR begins_with(CustomerName,:val) ', 
    ExpressionAttributeValues: { 
        ':value': {'S':'S'},
        ':val':{'S':'E'},
      },
    Select: 'ALL_ATTRIBUTES', 
 };

 dynamodb.scan(params, function(err, data) {
    if (err) ppJson(err); // an error occurred
    else ppJson(data); // successful response
});
Run Code Online (Sandbox Code Playgroud)

但我不能尝试使用botot3.

以下是我迄今为止可以实现的目标

response = table.scan(
                  Select= 'ALL_ATTRIBUTES',
                  FilterExpression=Attr('CustomerName').begins_with("S") 
                  )
Run Code Online (Sandbox Code Playgroud)

我无法理解如何添加OR条件.如果我添加,则显示错误

Jit*_*hPS 23

对于AND'和'用于和'''|' 用来

  response = table.scan(
              Select= 'ALL_ATTRIBUTES',
              FilterExpression=Attr('CustomerName').begins_with("S") | Attr('CustomerName').begins_with("S") 
              )
Run Code Online (Sandbox Code Playgroud)

  • @JoeCabezas您可以在这里找到官方文档中对运算符的引用:http://boto3.readthedocs.io/en/latest/guide/dynamodb.html#querying-and-scanning _"您还可以链接条件一起使用逻辑运算符:&(和),|(或)和〜(not).例如,这将扫描first_name以J开头且其account_type为super_user的所有用户:"_ (4认同)