Python MongoDB Interface

Source: Internet
Author: User
Tags mongodb interface

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.