2017-10-07 47 views
-1

在DynamoDB表,我有161712記錄當任何適用的過濾器,我已經收到掃描計數值只有10589蟒蛇DynamoDB掃描操作不會返回所有記錄

這是MYTABLE元

{ 
    "AttributeDefinitions": [ 
    { 
     "AttributeName": "question_id", 
     "AttributeType": "N" 
    }, 
    { 
     "AttributeName": "timestamp", 
     "AttributeType": "S" 
    } 
    ], 
    "TableName": "users_answers", 
    "KeySchema": [ 
    { 
     "AttributeName": "timestamp", 
     "KeyType": "HASH" 
    }, 
    { 
     "AttributeName": "question_id", 
     "KeyType": "RANGE" 
    } 
    ], 
    "TableStatus": "ACTIVE", 
    "CreationDateTime": "2017-09-12T12:33:22.615Z", 
    "ProvisionedThroughput": { 
    "LastIncreaseDateTime": "2017-09-12T16:46:26.742Z", 
    "NumberOfDecreasesToday": 0, 
    "ReadCapacityUnits": 80, 
    "WriteCapacityUnits": 80 
    }, 
    "TableSizeBytes": 16014441, 
    "ItemCount": 161712 
} 

當我這樣做掃描上面的表格操作將只得到10589條記錄

table = dynamo.get_table('answer_options') 
x = table.scan() 

請建議我如何從表中取整記錄

ENV:提前蟒蛇3.5.1,燒瓶dynamodb

感謝

回答

2

DynamoDB只有每個請求返回1MB。您必須遍歷併發出多個請求,直到獲得完整的數據集。

DynamoDB docs

DynamoDB進行分頁從掃描操作的結果。通過分頁,掃描結果被分成1MB(或更小)數據的「頁面」。應用程序可以處理結果的第一頁,然後處理第二頁,等等。

單個掃描將只返回符合1 MB大小限制的結果集。要確定是否有更多的成果,並在同一時間對它們進行檢索一個頁面,應用程序應該做到以下幾點:

  1. 檢查低級別掃描結果:

    • 如果結果包含LastEvaluatedKey元素,請繼續執行步驟2.
    • 如果結果中沒有LastEvaluatedKey,則不再有要檢索的項目。
  2. 構造一個新的掃描請求,使用相同的參數與前一個,但是此時,從步驟1取LastEvaluatedKey值並且使用它作爲在新的掃描請求的ExclusiveStartKey參數。

  3. 運行新的掃描請求。

  4. 轉到步驟1

+0

感謝讓我查 – Robert