我正在使用 Pynamodb
与 dynamodb
进行交互。
但是,即使有多个项目,last_evaluated_key 也始终返回 null。
当我运行此查询时
results = RecruiterProfileModel.profile_index.query(
hash_key=UserEnum.RECRUITER,
scan_index_forward=False,
limit=1,
)
如果我尝试获取这个值
results.last_evaluated_key
它总是返回null
。
但是,如果我转储 results
对象,它会返回
{
"page_iter": {
"_operation": {},
"_args": [
"recruiter"
],
"_kwargs": {
"range_key_condition": null,
"filter_condition": null,
"index_name": "PROFILE_INDEX",
"exclusive_start_key": {
"sk": {
"S": "PROFILE#6ab0f5bc-7283-4236-9e37-ea746901d19e"
},
"user_type": {
"S": "recruiter"
},
"created_at": {
"N": "1677398017.685749"
},
"pk": {
"S": "RECRUITER#6ab0f5bc-7283-4236-9e37-ea746901d19e"
}
},
"consistent_read": false,
"scan_index_forward": false,
"limit": 1,
"attributes_to_get": null
},
"_last_evaluated_key": {
"sk": {
"S": "PROFILE#95a4f201-2475-45a7-b096-5167f6a4d639"
},
"user_type": {
"S": "recruiter"
},
"created_at": {
"N": "1677398017.68518"
},
"pk": {
"S": "RECRUITER#95a4f201-2475-45a7-b096-5167f6a4d639"
}
},
"_is_last_page": false,
"_total_scanned_count": 2,
"_rate_limiter": null,
"_settings": {
"extra_headers": null
}
},
"_map_fn": {},
"_limit": 0,
"_total_count": 1,
"_index": 1,
"_count": 1,
"_items": [
{
"company_name": {
"S": "fletcher-rodriguez"
},
"created_at": {
"N": "1677398017.685749"
},
"last_name": {
"S": "craig"
},
"first_name": {
"S": "tyler"
},
"designation": {
"S": "manager"
},
"verification_status": {
"S": "pending"
},
"sk": {
"S": "PROFILE#6ab0f5bc-7283-4236-9e37-ea746901d19e"
},
"user_type": {
"S": "recruiter"
},
"email": {
"S": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e78188908b82958c86938f9ea78f829589868983829dc984888a" rel="noreferrer noopener nofollow">[email protected]</a>"
},
"pk": {
"S": "RECRUITER#6ab0f5bc-7283-4236-9e37-ea746901d19e"
}
}
]
}
您可以清楚地看到那里存在 last_evaluated_key
。
我在这里很困惑。
请帮忙。我有最后期限要满足。预先感谢您。
编辑:
这是一个视频附件,尝试以不同方式获取 last_eveluated_key
的值,但它们都返回 null
pynamodb last_evaluated_key issue Gdrive video
最佳答案
query()
返回的 result
是 ResultIterator
对象,它是一个迭代器。它的 last_evaluated_key
是您从迭代器中提取的最后一项的键,而不是 DynamoDB。由于您的代码尚未要求检索任何项目,因此未设置 last_evaluated_key
。
您需要处理结果
中的部分或全部项目:
for item in results:
print(item)
return results.last_evaluated_key
然后您将获得您处理的最后一项的 key 。
关于python - pynamodb last_evaluated_key 始终返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75570820/