Pash1986 commited on
Commit
cf4d742
1 Parent(s): b4e6eee

Upload 2 files

Browse files
Files changed (2) hide show
  1. ingest.py +35 -0
  2. requirements.txt +2 -0
ingest.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from pymongo import MongoClient
3
+ import datasets
4
+ from datasets import load_dataset
5
+ from bson import json_util
6
+
7
+
8
+ uri = os.environ.get('MONGODB_ATLAS_URI')
9
+ client = MongoClient(uri)
10
+ db_name = 'sample_mflix'
11
+ collection_name = 'embedded_movies'
12
+
13
+ embedded_movies_collection = client[db_name][collection_name]
14
+
15
+ dataset = load_dataset("AIatMongoDB/embedded_movies")
16
+
17
+ insert_data = []
18
+
19
+ for movie in dataset['train']:
20
+ doc_movie = json_util.loads(json_util.dumps(movie))
21
+ insert_data.append(doc_movie)
22
+
23
+ if len(insert_data) == 1000:
24
+ embedded_movies_collection.insert_many(insert_data)
25
+ print("1000 records ingested")
26
+ insert_data = []
27
+
28
+ if len(insert_data) > 0:
29
+ embedded_movies_collection.insert_many(insert_data)
30
+ insert_data = []
31
+
32
+ print("Data Ingested")
33
+
34
+
35
+
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pymongo
2
+ datasets