# Hash tables inside hash table - data modelling problem

**URL:** <https://discuss.aerospike.com/t/hash-tables-inside-hash-table-data-modelling-problem/11745>\
**Category:** Use Cases\
**Created:** [November 13, 2024, 2:50pm UTC](https://discuss.aerospike.com/t/hash-tables-inside-hash-table-data-modelling-problem/11745 "2024-11-13T14:50:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nikki](https://avatars.discourse-cdn.com/v4/letter/n/6a8cbe/32.png) [@Nikki](https://discuss.aerospike.com/u/Nikki)\
**Post date:** [November 13, 2024, 2:50pm UTC](https://discuss.aerospike.com/t/hash-tables-inside-hash-table-data-modelling-problem/11745/1 "2024-11-13T14:50:05Z")

</div>

Hello!

I want to store in Aerospike the maps of profiles(profileId(int type) → string) by some string keys (these keys count not limited). In other words - hash tables inside hash table: map[string]map[int]string.

And I have two use cases:

1. Fast find all profiles by string key
2. Fast find concrete profile by profileId key and string key

I found the next solution: store all in one record. Every bin will have the following form:

`Bin("keyString", map[int]string{1: "profileData1", 2: "profileData2", ...})`

For case1 I can use ‘Get’ function by key and binName.

For case2 - ‘MapGetByKeyOp’ function with binName, int key and MapReturnType.VALUE parameters.

But I found that exists limit on bin count in one record - 32767. It’s broke my solution but I cannot find any other.

Any ideas? Thank you.

---

<div class="post-metadata">

**Author:** ![namkazt](https://avatars.discourse-cdn.com/v4/letter/n/e0b2c6/32.png) [@namkazt](https://discuss.aerospike.com/u/namkazt)\
**Post date:** [November 19, 2024, 8:16am UTC](https://discuss.aerospike.com/t/hash-tables-inside-hash-table-data-modelling-problem/11745/2 "2024-11-19T08:16:10Z")

</div>

Hi Nikki,

Here is my thought about your problems and how to solved it.

Your issues: you probably should not design a set like that as i thought very bad design. (remember aerospike also have limit in record size too )

1, For fast way to get all profiles by a key string, you can use a secondary index

2, For find concrete profile you can use Primary key directly

Set: user\_profiles PK = string key + “|” + profileId (int) Bins:

- key string - secondary index
- profile data ( your bins for store data )

Assume you are using golang lib

So for question 1: We just create a query statement with filter equal to that bin we already indexed, response will be very fast as it only search in memory ( remember no expression operation here )

For question 2: Just get directly record by key combined from your key string and profile id

Hope that help. ( sorry if it feel aggressive as my english is not good so i just write it straigth what i thought )
