MongoDB与python连接及读取信息

# -*- coding: utf-8 -*-
__author__ = 'zww'

import pprint
from pymongo import MongoClient
from bson import json_util as jsonb
import json
import csv

client = MongoClient('localhost', 27017)
db = client.xxx
col = db.xxx
content = jsonb.dumps(list(col.find({"xxx": xxx})))

des_file = open('xxx','ab')
csv_writer = csv.writer(des_file)

with des_file as f:
    json.dump(content,f)

你可能感兴趣的:(python-基础)