Python MongoDB Interface
MongoDB is a database based on distributed file storage. Written by the C + + language. Designed to provide scalable, high-performance data storage solutions for WEB applications.
At the same time, MongoDB is a product between relational and non-relational databases and is a good implementation of NoSQL.
This document uses the Pymongo module to invoke MongoDB with Python
Tool class implementation
fromPymongoImportMongoclientmongodb_name= ' Dev_map 'Client=Mongoclient ("mongodb://localhost:27017") Mongua=Client[mongodb_name]defTimestamp (CLS):ImportTimereturn int(Time.time ())classModelutil ():@classmethod defAdd (CLS, TABLE_NAME, item): Table=Mongua[table_name] item["deleted"]= FalseTs=Timestamp () item["Created_time"]=TS item["Updated_time"]=TS Table.insert_one (item)@classmethod defDelete (CLS, table_name, conditions): item=Cls.query (table_name, conditions) item["deleted"]= TrueCls.update (table_name, item)@classmethod defQuery (CLS, TABLE_NAME, conditions): Table=Mongua[table_name] Item=Table.find_one (conditions)returnItem@classmethod defEXISTS (CLS, TABLE_NAME, conditions): Table=Mongua[table_name] Item=Table.find_one (conditions)returnItem is not None @classmethod defUpdate (CLS, TABLE_NAME, item): Table=Mongua[table_name] item["Updated_time"]=Timestamp () Table.save (item)
Summary
With Mongdb, you can access the data collection as a table, on the other hand, the type of the entry can be a JSON-like unstructured data that corresponds exactly to the dict in Python, so it's easy to use
Python MongoDB Interface