amazon dynamodb - Querying items by secondary index with only secondary hashKey, no rangeKey -


i have table in dynamodb primary hashkey itemid. items have relationship parent item, besides querying them itemid, want able retrieve children of parent, added attribute parentid.

now want able find children given parent. reading docs, understand need create secondary index, fail understand rangekey should , how construct dynamodbqueryexpression<item> without setting range condition.

i missing fundamental guess...

i'm assuming table looks this:

itemid (hash key), parentid

you need create global secondary index on table looks this:

parentid (hash key), itemid (range key)

now, can query set parent id in keyconditionexpression.

here's example written in ruby:

resp = aws::dynamodb::client.new.query(   table_name: "mytablename",   select: "specific_attributes",   attributes_to_get: ["parentid", "itemid"],   key_condition_expression: "parentid = <parent_whose_children_you_want>",   exclusive_start_key: <query_start_key_from_prev_query> ) 

once dynamodb hits 1mb of data, it'll return , give lastevaluatedkey can use exclusivestartkey next query. way can page through db.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -