Skip to content

Database Library (MongoDB)

Trevor Geene edited this page Jan 4, 2021 · 6 revisions

THIS PAGE IS CURRENTLY OUT OF DATE

Using MongoDB

Install Nessicary Requirements:

pip install pymongo

Example Config:

db_config = {
    'driver': 'mongodb',
    'host': '127.0.0.1',
    'port': '27017',
    'database': 'flask-mvc-framework',
    'authorize': 'admin',
    'username': '',
    'password': ''
}

Example Usage

insert = {
	'example_field_1': "test string",
	'example_field_2': 3,
	'example_field_3: False
}
insert = database_helper.clean_dict(insert)
insert_id = db.insert_one('example_db_table', insert)

Function List

Function Example
Generate ObjectID by String db.o_id(id='')
Get One Record db.get_one(table_name='', where_obj={}, col_select='*')
Get Multiple Records db.get(table_name='', where_obj={}, col_select='*')
Get Record Count db.get_count(table_name='', where_obj={})
Get by Aggregate db.aggregate(collection_name='', pipeline=[], options={})
Insert One Record db.insert_one(table_name='', data_obj={})
Insert Multiple Records db.insert_many(table_name='', data_obj=[])
Update Record(s) db.update(table_name='', where_obj={}, data_obj={})
Delete One Record db.delete_one(table_name='', where_obj={})
Delete Multiple Records db.delete_many(table_name='', where_obj={})