ani*_*ako 4 amazon-dynamodb dynamo-local
尝试在dynamodb中使用IN操作,但出现以下错误。有人可以帮我替代解决方案吗?
var params = {
TableName : "table_name",
FilterExpression : "id IN ("+Object.keys(profileIdObject).toString()+ ")",
ExpressionAttributeValues : profileIdObject
Run Code Online (Sandbox Code Playgroud)
};
错误:: {
"message": "Invalid FilterExpression: The IN operator is provided with too many operands; number of operands: 119",
"code": "ValidationException",
"time": "2018-02-13T08:48:02.597Z",
"statusCode": 400,
"retryable": false,
"retryDelay": 25.08276239472692
Run Code Online (Sandbox Code Playgroud)
}
小智 6
根据 dynamodb 文档,IN 比较器的最大操作数数量为 100
因此,您可以分为许多操作,例如:
FilterExpression : "id IN (1,2,3, ....) OR id IN (101,102,103,...) ..."
使用此功能:
let getFilterExp = function (x) {
let arr = []
let currentIndex = 0
let counter = 0
let max = 99
arr[currentIndex] = {}
for (let y in x) {
if (counter < max) {
arr[currentIndex][y] = x[y]
counter++
}
else {
currentIndex++
arr[currentIndex] = {}
arr[currentIndex][y] = x[y]
counter = 0
}
}
let exp = ''
for (let i = 0; i < arr.length; i++) {
if (i == 0) {
exp += "id IN (" + Object.keys(arr[i]).toString() + ")"
}
else {
exp += " OR id IN (" + Object.keys(arr[i]).toString() + ") "
}
}
return exp
}
Run Code Online (Sandbox Code Playgroud)
其中 x 是您的情况下的 profileIdObject
let filterExp = getFilterExp(profileIdObject )
Run Code Online (Sandbox Code Playgroud)
根据文档:
IN比较器的最大操作数为100
在这里找到:https : //docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-expression-parameters
您需要分多个批次执行查询/扫描,在您的情况下,Object.keys(profileIdObject).toString()第一批次为100,第二批次为19。然后合并结果。
| 归档时间: |
|
| 查看次数: |
586 次 |
| 最近记录: |