Update README.md
Browse files
README.md
CHANGED
@@ -180,4 +180,49 @@ The dataset is suited for a range of applications, including:
|
|
180 |
0.010051459
|
181 |
]
|
182 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
```
|
|
|
180 |
0.010051459
|
181 |
]
|
182 |
}
|
183 |
+
```
|
184 |
+
|
185 |
+
## Ingest Data
|
186 |
+
|
187 |
+
The small script `ingest.py` can be used to load the data into your MongoDB Atlas cluster.
|
188 |
+
|
189 |
+
```
|
190 |
+
pip install pymongo
|
191 |
+
pip install datasets
|
192 |
+
## export MONGODB_ATLAS_URI=<your atlas uri>
|
193 |
+
```
|
194 |
+
The `ingest.py`:
|
195 |
+
```python
|
196 |
+
import os
|
197 |
+
from pymongo import MongoClient
|
198 |
+
import datasets
|
199 |
+
from datasets import load_dataset
|
200 |
+
from bson import json_util
|
201 |
+
|
202 |
+
|
203 |
+
uri = os.environ.get('MONGODB_ATLAS_URI')
|
204 |
+
client = MongoClient(uri)
|
205 |
+
db_name = 'sample_mflix'
|
206 |
+
collection_name = 'embedded_movies'
|
207 |
+
|
208 |
+
embedded_movies_collection = client[db_name][collection_name]
|
209 |
+
|
210 |
+
dataset = load_dataset("AIatMongoDB/embedded_movies")
|
211 |
+
|
212 |
+
insert_data = []
|
213 |
+
|
214 |
+
for movie in dataset['train']:
|
215 |
+
doc_movie = json_util.loads(json_util.dumps(movie))
|
216 |
+
insert_data.append(doc_movie)
|
217 |
+
|
218 |
+
if len(insert_data) == 1000:
|
219 |
+
embedded_movies_collection.insert_many(insert_data)
|
220 |
+
print("1000 records ingested")
|
221 |
+
insert_data = []
|
222 |
+
|
223 |
+
if len(insert_data) > 0:
|
224 |
+
embedded_movies_collection.insert_many(insert_data)
|
225 |
+
insert_data = []
|
226 |
+
|
227 |
+
print("Data Ingested")
|
228 |
```
|