# req - create connection only
m0 = MongoDB()
status(m0.get_current_status(), 'only connection')
# req - create database with validation
m0.create_db('try000')
status(m0.get_current_status(), 'only database')
# 2
m = MongoDB(database_name='try001')
status(m.get_current_status(), 'only database - part 2')

# req - drop db by name
mm = MongoDB(database_name='DELETE_ME')
mm.create_collection(collection_name='Temporary')
mm.insert(get_dummy_data())
status(mm.get_database_names(), msg='create and delete db')
print('collection created - ', mm.get_collection_names())
mm.drop_db(database_name='DELETE_ME')
print('DB names after dropping - ', mm.get_database_names())
# req - trying to recreate DB with old details RAISE EXCEPTION
# mm.insert(get_dummy_data())
# print('DB names after dropping - ', mm.get_database_names())

# req - get db names
y = MongoDB()
status(y.get_database_names(), 'database names')

# req - get collection names
y = MongoDB(database_name='try001')
y.create_collection(collection_name='collection001')
Example #2
0
 def save_to_mongo(self,dic):
         mon = MongoDB()
         if not mon.find({'内容':self.weibo_content}):
             mon.insert(dic)
Example #3
0
 def save_to_mongo(self, dic):
     mon = MongoDB()
     if not mon.find({'内容': self.weibo_content}):
         mon.insert(dic)