python3使用pymongo查询mongodb

from pymongo import MongoClient
from urllib import parse
import pprint


def to_laike_log(id):
    password = lambda: parse.quote('password')
    password = password
    db_name = 'db_name'
    ip = 'ip'  #ip地址
    key = 'key'  # 端口
    url = 'url'
    mango_url = url % ('user', password, ip, key, db_name) 
    # mongodb://test:[email protected]:7000/udc_test
    conn = MongoClient(mango_url)
    db = conn.udc_test  # db名称
    table = db.thread_to_laike  # 表名称 
    result = table.find({'id': id})   # 查询多个
    for i in result:
        pprint.pprint(i)
        

to_laike_log('1')

你可能感兴趣的:(python3使用pymongo查询mongodb)