title: How to store circular document inside table?
body: <p>I'm new to NoSQL database design. For my application I have two entities to store in database. I will use JSON-like notation to represent structure.</p>
  
  <pre><code>User {
     id: Uuid,
     telegram_user_id: int64
     room: Optional&lt;Room&gt;,
     nickname: String,
  }
  
  Room {
     id: Uuid,
     first_user: User
     second_user: Optional&lt;User&gt;
  }
  </code></pre>
  
  <p>So I basically have <code>User</code> which can create and join a <code>Room</code>. When <code>User</code> creates room he's already joined inside is.</p>
  
  <p>I need to do several things.</p>
  
  <ol>
  <li>Create a new User without room.</li>
  <li>Attach a room to User.</li>
  <li>Easily find User by it's <code>telegram_user_id</code>.</li>
  <li>Add <code>Room.second_user</code> when another user joins the room, when I have <code>Room.id</code> and <code>User.telegram_user_id</code>.</li>
  <li>Find <code>Room.second_user</code>, when I have <code>User.telegram_user_id</code>.</li>
  </ol>
  
  <p>Most queries will be when querying <code>User</code> by it's <code>telegram_id</code> and when finding second user inside a room, using first user <code>telegram_user_id</code>.</p>
  
  <p>I don't understand how to design it well for DynamoDB. 
  I could possibly use relational data model and do several queries. In that example <code>User.room</code> will be just <code>Room.id</code> and <code>Room.first_user</code>,<code>Room.second_user</code> will be <code>User.id</code>.</p>
  
  <p>To find second user, by first user <code>telegram_user_id</code> I would have to do several queries.</p>
  
  <ol>
  <li>Finding first User</li>
  <li>Using a <code>User.room</code> as partition key to find <code>Room</code></li>
  <li>Then finding second <code>User</code> by id in <code>Room.second_user</code>.</li>
  </ol>
  
  <p>But it feels not right to do it with several independent queries.</p>
  
  <p>But I don't know how to implement my requirements well without relational data model.</p>
  
  <p>How to design this table?</p>