title: what am I missing here? pymongo
body: <pre><code>from pymongo import MongoClient
  from bson.objectid import ObjectId
  
  class AnimalShelter(object):
      #CRUD operations for animals collection in MongoDB
      
      def __init__(self, username, password):
          #initializing Mongo Client
          self.client = MongoClient('mongodb://%s:%s@127.0.0.1:53310/AAC' % (username, password))
          self.database = self.client['AAC']
          
                                    
          # Method to implement the C in CRUD
      def create(self, data):
          if data is not None:
              if data:
                  self.database.animals.insert_one(data)
                  return True
          else:
              return False
              
              
      def read(self, search):
          if search is not None:
              if search:
                  searchResult = self.database.animals.find(search)
                  return searchResult
          else:
              exception = (&quot;Nothing to see here folks.&quot;)
                  return exception
  </code></pre>
  <p>This is my class that I created, I am trying to test the output.</p>
  <pre><code>from animal_shelter import AnimalShelter
  
  #defining data
  
  data = {&quot;age_upon_outcome&quot; : &quot;3 years&quot;,
      &quot;animal_id&quot; : &quot;A746874&quot;,
      &quot;animal_type&quot; : &quot;Cat&quot;,
      &quot;breed&quot; : &quot;Domestic Shorthair Mix&quot;,
      &quot;color&quot; : &quot;Black/White&quot;,
      &quot;date_of_birth&quot; : &quot;2014-04-10&quot;,
      &quot;datetime&quot; : &quot;2017-04-11 09:00:00&quot;,
      &quot;monthyear&quot; : &quot;2017-04-11T09:00:00&quot;,
      &quot;name&quot; : &quot;&quot;,
      &quot;outcome_subtype&quot; : &quot;SCRP&quot;,
      &quot;outcome_type&quot; : &quot;Transfer&quot;,
      &quot;sex_upon_outcome&quot; : &quot;Neutered Male&quot;,
      &quot;location_lat&quot; : 30.5066578739455,
      &quot;location_long&quot; : -97.3408780722188,
      &quot;age_upon_outcome_in_weeks&quot; : 156.767857142857}
  
  #search criteria
  search = {&quot;animal_id&quot;:&quot;A746874&quot;}
  
  #instantiating an object
  assignment = AnimalShelter()
  
  #calling the method
  success = assignment.create(data)
  print(success)
  
  #call read method
  results = assignment.read(search)
  print(results)
  </code></pre>
  <p>I keep getting this error which I am having trouble understanding and correcting. I thought I was adding or importing the database when I initialized the mongo client. So how is it that my object doesn't have a database?</p>
  <pre><code>TypeError                                 Traceback (most recent call last)
  &lt;ipython-input-22-5434d1614df4&gt; in &lt;module&gt;
       26 
       27 #calling the method
  ---&gt; 28 success = assignment.create(data)
       29 print(success)
       30 
  
  AttributeError: 'AnimalShelter' object has no attribute 'database'
  </code></pre>
  <p>I am unsure about how to actually correct this. Is there a connection that I am not making between my class that I am creating and the mongo database that I am wanting to use?</p>