title: Querying Mongodb Database documents of same structure and displaying specific sub-fields in HTML
body: <p>I try to access the MongoDB database documents and list some of the fields in tabular format in HTML.
  The mongodb document has the following structure:</p>
  
  <pre><code>{
    "id" : "2421F225",
    "termsAndConditions" : "T&amp;C to be respected",
    "offererBranchId" : "CD71",
    "requesterBranchId" : "EB71",
    "accepted" : "2017-05-24T09:38:25.750Z",
    "services" : [ {
    "name" : "Processed Data",
    "Level" : [ "Country" ]
    } ]
  }
  </code></pre>
  
  <ol>
  <li>First I wanted to fetch all the documents with a particular structure,i.e all documents with the above structure from the database.  What I try to mean is, I want all the documents to be queried with the same fields names and subfields names as above.</li>
  </ol>
  
  <p>In the following code, I could only fetch the documents with a particular condition but not a structure as a condition itself.</p>
  
  <pre><code>    app = Flask(__name__)
      app.config['MONGO_DBNAME'] = 'demo'
      app.config['MONGO_URI'] = 'mongodb://xx@x.mlab.com:x/demo'
      mongo = PyMongo(app)
  
      @app.route('/data')
      def frenchinput():
      users=mongo.db.users
      x=users.find({'termsAndConditions':"T&amp;C to be respected"})
      return render_template('frenchinput.html',query=x)
  </code></pre>
  
  <ol start="2">
  <li><p>After fetching all the documents, I wanted to display some of the fields results in HTML in my web application.I am able to display the fields which all are on the upper level in the document for eg. the fields 'id', 'termsAndConditions' etc. But I am not able to display those which are nested i.e.'name' under 'services' in the above document. I used the following code to display the first level fields.</p>
  
  <pre><code>{% for field in query %}
  &lt;table&gt;
  &lt;tr&gt;
      &lt;td&gt;{{ field['id']}}&lt;/td&gt;
      &lt;td&gt;{{ field['termsAndConditions']}}&lt;/td&gt;
      &lt;td&gt;{{ field['services.name']}}&lt;/td&gt; &lt;!--The code which did not work--&gt;
  &lt;/tr&gt;
  &lt;/table&gt;                 
  {% endfor %}
  </code></pre></li>
  </ol>
  
  <p>Can anyone help me know how to fetch all documents with the same structure and the mistake I do while querying sub-fields for displaying in HTML.</p>