2016-06-09 74 views
4

我試圖做dynamodb 表掃描多個條件下面是這是在JavaScript如何有FilterExpression在dynamodb

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 
}); 

但我不能嘗試使用botot3相同的代碼。

下面是我能做到到目前爲止

response = table.scan(
        Select= 'ALL_ATTRIBUTES', 
        FilterExpression=Attr('CustomerName').begins_with("S") 
       ) 

我無法理解如何添加OR條件。如果我添加,它顯示錯誤

回答

5

對於AND'&'被使用,對於OR'|'使用

response = table.scan(
       Select= 'ALL_ATTRIBUTES', 
       FilterExpression=Attr('CustomerName').begins_with("S") | Attr('CustomerName').begins_with("S") 
      ) 
+0

這是什麼來源?,謝謝 –

+0

@Joe我不明白你在問什麼 – JithPS

+0

boto3文檔很難得到,謝謝反正 –

0

您可以創建一個字符串比較= [ 「A = B」,「C BEGINS_WITH VAL '],然後用加入他們' 和」。加入(比較)

爲您創建過濾表達式'a = b和c starts_with val'

相關問題