1. 程式人生 > >MongoDB與python連線及讀取資訊

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)