MongoDB数据可以通过以下几种方法进行导出:
mongodump --db <database_name> --out <output_directory>
使用以下命令导出指定集合:
mongodump --db <database_name> --collection <collection_name> --out <output_directory>
mongoexport --db <database_name> --collection <collection_name> --out <output_file.json>
from pymongo import MongoClient
import json
client = MongoClient()
db = client[<database_name>]
collection = db[<collection_name>]
cursor = collection.find()
with open('<output_file.json>', 'w') as f:
for document in cursor:
json.dump(document, f)
f.write('\n')