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')