title: Wrong group query when trying to build dynamically
body: <p>I am trying to working on a query builder and the example/content is just imaginary.</p>
  
  <pre><code>query = from en in Data.InfectionRevision
  query = from q in query, select: map(q, [:is_complete, :is_active])
  
  query = from(q in query,select_merge: %{"$aggregate": %{"$max": %{^"revision_id" =&gt; max(q.revision_id)}}})
  query = from(q in query,group_by: q.encounter_id,
   select_merge: %{"$group" =&gt; %{^"encounter_id" =&gt; q.encounter_id}})
  </code></pre>
  
  <p>But the query I get is having incorrect key for group, although I have passed correct key while building query. this is what I got </p>
  
  <pre><code>#Ecto.Query&lt;from i0 in Data.InfectionRevision, group_by: [i0.encounter_id],
   select: merge(merge(
     map(i0, [:is_complete, :is_active]), 
     %{"$aggregate": %{"$max": %{^"revision_id" =&gt; max(i0.revision_id)}}}), 
     %{"$group" =&gt; %{^"revision_id" =&gt; i0.encounter_id}})&gt;
  </code></pre>
  
  <p><code>%{"$group" =&gt; %{^"revision_id" =&gt; i0.encounter_id}}</code> should be actually <code>%{"$group" =&gt; %{^"encounter_id" =&gt; i0.encounter_id}}</code>
  What Step or part of the query I am building wrong? How to fix it?</p>
  
  <p>Note:</p>
  
  <ul>
  <li><a href="https://github.com/tanweerdev/has_many_preload" rel="nofollow noreferrer">sample project </a> on which you can run/build above queries</li>
  <li>Please ignore the query content, it might not makes sense because its just an example and should work  dynamically as its part of dynamic query builder</li>
  <li>I need to build query step by step from passed params dynamically</li>
  </ul>