Ryu
  • ๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป Ryu / software_engineer
  • โœจResume
  • Python3
    • Python3 ๊ฐ€์ƒํ™˜๊ฒฝ ์„ค์ •ํ•˜๊ธฐ
      • Python3 vs Python2
      • Pyenv
      • Venv
      • Pip
    • Flask
      • Flask ์„ค์น˜ํ•˜๊ธฐ
      • API Server ๋งŒ๋“ค๊ธฐ
    • REST API
    • Command Line ํ™œ์šฉํ•˜๊ธฐ
    • Module ์‚ฌ์šฉํ•˜๊ธฐ
      • Pickle - ์ž๋ฃŒํ˜•์„ ํŒŒ์ผ๋กœ ์ €์žฅํ•  ๋•Œ
    • MongoDB connection
      • Pymongo
    • WSGI
      • ๐Ÿ’กWSGI ๊ฐ€ ํ•„์š”ํ•œ ์ด์œ 
      • Web Server / WSGI / Middleware / Application ๊ตฌ์กฐ
      • WSGI Middleware ์ข…๋ฅ˜
      • Gunicorn
        • Gunicorn vs Uwsgi
    • Dockerize
      • ๐Ÿ’กDockerize ๊ฐ€ ํ•„์š”ํ•œ ์ด์œ 
      • 1. Create Dockerfile
        • Gunicorn ์œผ๋กœ nginx ์™€ app ์—ฐ๊ฒฐํ•˜๊ธฐ
    • Kubernetes ๋กœ ๋ฐฐํฌํ•˜๊ธฐ
      • ๐Ÿ’กKubernetes ๊ฐ€ ํ•„์š”ํ•œ ์ด์œ 
      • Helm ์‚ฌ์šฉํ•˜๊ธฐ
      • Helm ์œผ๋กœ k8s ์— ์•ฑ ๋ฐฐํฌํ•˜๊ธฐ
  • Open Tracing (์ •๋ฆฌ์ค‘)
    • Open Tracing ์ด๋ž€ ๋ฌด์—‡์ธ๊ฐ€
    • Python OpenTracing Example
    • Jaeger, Jaeger UI
    • Python Jaeger Tutorial
    • Zipkin ์•Œ์•„๋ณด๊ธฐ
    • Jaeger-client ๋ฆฌ์ŠคํŒ…
  • Microservice Architecture
    • Netflix์˜ MSA ์ปจ์…‰
      • โšก๏ธ MSA ๋ฅผ ๋„์ž…ํ• ๋•Œ ๊ณ ๋ คํ•ด์•ผํ•  ์ ๋“ค
  • Paper
    • Dynamo: Amazonโ€™s Highly Available Key-value Store
      • 1. Introduction
      • 2. Background
      • 3. Related Work
        • Related Paper) Pastry, Chord
        • Byzantine Fault Tolerance
      • 4. System Architecture
        • 4.1 System Interface
        • 4.2 Partitioning
        • 4.3 Replication
        • Hash Function
  • Frontend
    • CommonJS ์™€ AMD
    • RequireJS
    • WebSocket
      • WebSocket vs Socket.io
      • polling vs long polling vs streaming
    • Vue.js
      • Vue.js ์—์„œ WebSocket ์‚ฌ์šฉํ•˜๊ธฐ
      • [ํ”„๋กœ์ ํŠธ] Vue, Vuex, AntDesignVue ๋กœ ์šด์˜ํˆด ๋งŒ๋“ค๊ธฐ
    • React x Redux ๋กœ ํ”„๋กœ์ ํŠธ ๋งŒ๋“ค๊ธฐ
      • 0. React, Redux ๋ฅผ ์„ ํƒํ•œ ์ด์œ 
      • 1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ณ  Webpack4 ์ ์šฉํ•˜๊ธฐ
      • 2. React ์™€ ReactDOM ์ ์šฉํ•˜๊ธฐ
      • 3. Material UI ์ ์šฉํ•˜๊ธฐ
  • Data Engineering
    • Spark
      • Spark ์ด๋ž€?
      • ๊ฐ ๋ฐ๋ชฌ์˜ ์—ญํ•  Driver, Master, Worker
      • ์žฅ๋‹จ์  / ํ•จ๊ป˜์‚ฌ์šฉํ•˜๋Š” ํˆด / ์‚ฌ์šฉ ์‚ฌ๋ก€
  • Service Mesh (์ •๋ฆฌ์ค‘)
    • RPC
    • gRPC - Python Server ๋งŒ๋“ค๊ธฐ
      • step 2.
Powered by GitBook
On this page
  • Install Pymongo
  • Export data from Database

Was this helpful?

  1. Python3
  2. MongoDB connection

Pymongo

Install Pymongo

$ pip install pymongo

Export data from Database

./export.py

import pymongo
from pymongo import MongoClient

def connect(config):
    host = config.get('host')
    port = config.get('port')
    username = config.get('username')
    password = config.get('password')
    db_name = config.get('database')
    uri = 'mongodb://%(host)s:%(port)s' % vars()

    client = MongoClient(uri, username=username, password=password)
    db = client[db_name]
    return client, db


def get_item(db, item_oid):
    try:
        return db.item.find_one({'_id': item_oid})
    except Exception as e:
        logger.error('failed to find item by id. error=%s' % str(e))
        return None


if __name__ == "__main__":
    parser = optparse.OptionParser()
    parser.add_option('--id', dest='id', default=None, type='string')
    (options, args) = parser.parse_args()

    if options.id is None:
        print_usage_and_exit()

    _id = options.id

    try:
        item_oid = ObjectId(_id)
    except Exception as e:
        logger.error('invalid id. error=%s' % str(e))
        print_usage_and_exit()

    client, db = connect(config)
    item = get_item(db, item_oid)
PreviousMongoDB connectionNextWSGI

Last updated 6 years ago

Was this helpful?