-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmongoDBTest
More file actions
22 lines (17 loc) · 860 Bytes
/
mongoDBTest
File metadata and controls
22 lines (17 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from pymongo import MongoClient
import csv
# Connect to MongoDB
client = MongoClient('mongodb+srv://mbillahmim:[email protected]/')
db = client.sample_mflix
# Access the collection
javaTestDataset = db.javaTestDataset
# Open a CSV file in write mode
with open('java_test_dataset.csv', 'w', newline='') as csvfile:
# Define the CSV writer
writer = csv.DictWriter(csvfile, fieldnames=['_id', 'func_name', 'docstring_tokens', 'url', 'sha', 'path', 'original_string', 'language', 'code', 'docstring', 'partition', 'helpers', 'repo', 'code_tokens']) # Provide fieldnames if needed
# Write the header (field names)
writer.writeheader()
# Iterate over documents in the collection
for document in javaTestDataset.find():
# Write each document as a row in the CSV file
writer.writerow(document)