Pash1986 commited on
Commit
24c5567
1 Parent(s): b5b4544

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +38 -3
README.md CHANGED
@@ -144,9 +144,44 @@ This dataset can be utilized for various purposes, including but not limited to:
144
  The snall script `ingest.py` can be used to load the data into your MongoDB Atlas cluster.
145
 
146
  ```
147
- pip install -r requirements.txt
148
- ## Set MONGODB_ATLAS_URI os variable
149
- python ingest.py
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
  ```
151
 
152
  ## Contact
 
144
  The snall script `ingest.py` can be used to load the data into your MongoDB Atlas cluster.
145
 
146
  ```
147
+ pip install pymongo
148
+ pip install datasets
149
+ ## export MONGODB_ATLAS_URI=<your atlas uri>
150
+ ```
151
+ The `ingest.py`:
152
+ ```python
153
+ import os
154
+ from pymongo import MongoClient
155
+ import datasets
156
+ from datasets import load_dataset
157
+ from bson import json_util
158
+
159
+
160
+ uri = os.environ.get('MONGODB_ATLAS_URI')
161
+ client = MongoClient(uri)
162
+ db_name = 'whatscooking'
163
+ collection_name = 'restaurants'
164
+
165
+ restaurants_collection = client[db_name][collection_name]
166
+
167
+ dataset = load_dataset("AIatMongoDB/whatscooking.restaurants")
168
+
169
+ insert_data = []
170
+
171
+ for restaurant in dataset['train']:
172
+ doc_restaurant = json_util.loads(json_util.dumps(restaurant))
173
+ insert_data.append(doc_restaurant)
174
+
175
+ if len(insert_data) == 1000:
176
+ restaurants_collection.insert_many(insert_data)
177
+ print("1000 records ingested")
178
+ insert_data = []
179
+
180
+ if len(insert_data) > 0:
181
+ restaurants_collection.insert_many(insert_data)
182
+ insert_data = []
183
+
184
+ print("Data Ingested")
185
  ```
186
 
187
  ## Contact