Code Monkey home page Code Monkey logo

python_code's Introduction

Python Code Utilities

This repository contains various utility classes and functions to facilitate working with different technologies such as MongoDB, message queues, Excel, text files, and MySQL. Each utility class is designed to provide simple and efficient ways to perform common operations.

Table of Contents

MongoDB Util

The MongoDB util provide convenient methods to interact with MongoDB databases. These include connecting to the database, performing CRUD operations, and handling collections.

Features

  • Connect to MongoDB
  • Create, read, update, and delete documents
  • Handle collections

Usage

# 使用示例
if __name__ == '__main__':
    db = MongoDB(host='localhost',
                 port=27017,
                 username=None,
                 password=None,
                 db_name='test',
                 collection_name='test')
    # 示例用法:
    # 保存数据
    info = {
        'name': '张三',
        'age': 20,
        'email': '[email protected]'
    }
    db.save_dict_to_collection(info)

    # 根据query_key更新
    info = {
        'name': '张三',
        'age': 20,
        'email': '[email protected]'
    }
    db.save_dict_to_collection(info, query_key='name')

    # 保存数据字典
    info = [
        {
            'name': '张三',
            'age': 20,
            'email': '[email protected]'
        },
        {
            'name': '李四',
            'age': 25,
            'email': '[email protected]'
        }
    ]
    db.save_dict_list_to_collection(info)
    # 查询集合所有数据
    db.find_documents()

    # 条件查询 查询 age 大于 18 的用户,并仅返回 name 和 email 字段,限制返回结果数量为 10
    db.find_documents(query={'age': {'$gt': 18}}, projection={'name': 1, 'email': 1}, limit=10)

    # 切换集合
    db.use(collection_name='test1')

python_code's People

Contributors

xyl123124 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.