MongoDB下载: https://www.mongodb.com/
可视化工具Robo 3T下载:https://robomongo.org/download
python中的操作
# 引入pymongo模块
import pymongo
读取数据库
import pandas as pd
def get_key_value(database, collection, key):
client = pymongo.MongoClient('localhost', 27017)
db = client['database']
table = db['collection']
data = pd.DataFrame(list(table.find()))
value = data['key']
return value
保存数据至数据库中
def save_to_Mongo(result):
# 数据储存到mongodb
try:
if db[MONGO_TABLE].insert_one(result):
print('存储到MongoDB成功', result)
except Exception:
print('存储到MongoDb失败', result)
MONGO_URl = 'localhost:27017'
MONGO_DB = 'database_name'
client = pymongo.MongoClient(MONGO_URl)
db = client[MONGO_DB]
MONGO_TABLE = 'collection_name'
更新换代数据库中数据
db[MONGO_TABLE].update_one(
{'_id': "匹配所需更改的集合"},
{'$set': {'所需更改的key':'更改的值'}})
将数据库压缩导出
mongodump --db database_name --collection collection_name --archive=database_name.tar.gz