makaleChatbotu / mongoDb.py
yonkasoft's picture
Upload 11 files
b9ab29b verified
from pymongo import MongoClient
import pandas as pd
#mongodb bağlantı ayarları
def get_mongodb(database_name='myDatabase',collection_name='new',host='localhost',port=27017):
"mongodb bağlantısı ve koleksiyon seçimi "
client=MongoClient(f'mongodb://{host}:{port}/')
db=client[database_name]
collection=db[collection_name]
return collection
"""#koleksiyonun varlığını kontrol eder.
def get_collection(self, collection_name):
#Get a collection if it exists, otherwise return None.
if self.check_collection_exists(collection_name):
return self.db[collection_name]
else:
print(f"Collection '{collection_name}' does not exist.")
return None"""
#dataseti mongodb ye yükleme
def dataset_read():
data=pd.read_csv('C:\gitProjects\medium-articles\medium_articles_no_text.csv')
data_dict=data.to_dict("records")
source_collection=get_mongodb(database_name='myDatabase',collection_name='data') #çeviri için kullanılan kaynak koleksiyonu
source_collection.insert_many(data_dict)
print("kayıt mongodb ye yüklendi." )
return source_collection
if __name__=='__main__':
dataset_read()