File size: 1,221 Bytes
b9ab29b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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()