title: How to access documents under a collection in MongoDB?
body: <p>I have a MongoDB database that has stock data stored on it. Each stock data is stored as a separate collection that the collection name is the stock name, and there are <code>id, time, open, high, low, close, volume</code> data stored in each collection for some days for each stock.You can see the structure of each collection in picture below:</p>
  <p><a href="https://i.stack.imgur.com/nh8AG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nh8AG.png" alt="enter image description here" /></a></p>
  <p>What I am trying to do is to find each collection, and store it's data as a new python dictionary separately. But my code doesn't work properly no errors.</p>
  <pre><code>from pymongo import MongoClient
  from pprint import pprint
  
  
  myclient = MongoClient(&quot;mongodb://localhost:27017/&quot;) #, username='mongo-admin', password='password')
  mydb = myclient[&quot;db-data-stock&quot;]
  pprint(mydb)
  posts = mydb.list_collection_names()
  
  
  for item in posts:
      for data in item:
          pprint(data)
  </code></pre>
  <p>And it only prints the name of the collections not the data inside of them!</p>
  <p>The output of the <code>posts</code> is a list with contents like:</p>
  <pre><code>['کیمیا',
   'ونفت',
   'اخزا807',
   'دیران',
   'وزمین',
   'کحافظ',
   'لبوتان']
  </code></pre>
  <p>And the output of nested <code>for</code>s is like:</p>
  <pre><code>'ر'
  'ک'
  'ب'
  'ا'
  'ف'
  'ق'
  'ث'
  'ج'
  'و'
  'ا'
  'ن'
  'ک'
  'ی'
  'ش'
  </code></pre>