MongoDB/product-catalog
收藏Hugging Face2024-06-04 更新2024-06-29 收录
下载链接:
https://hf-mirror.com/datasets/MongoDB/product-catalog
下载链接
链接失效反馈官方服务:
资源简介:
---
license: apache-2.0
---
## Ingest Data
The small script `ingest.py` can be used to load the data into your MongoDB Atlas cluster.
```
pip install pymongo
pip install datasets
## export MONGODB_ATLAS_URI=<your atlas uri>
```
The `ingest.py`:
```python
import os
from pymongo import MongoClient
import datasets
from datasets import load_dataset
from bson import json_util
uri = os.environ.get('MONGODB_ATLAS_URI')
client = MongoClient(uri)
db_name = 'ai_shop'
collection_name = 'products'
product_collection = client[db_name][collection_name]
dataset = load_dataset("MongoDB/product-catalog")
insert_data = []
for product in dataset['train']:
doc_product = json_util.loads(json_util.dumps(product))
insert_data.append(doc_product)
if len(insert_data) == 1000:
product_collection.insert_many(insert_data)
print("1000 records ingested")
insert_data = []
if len(insert_data) > 0:
product_collection.insert_many(insert_data)
insert_data = []
print("Data Ingested")
```
## Contact
For any queries or further information regarding this dataset, please open a disucssion.
The dataset named `MongoDB/product-catalog` contains product information and is used to store in the `products` collection of the `ai_shop` database in MongoDB.
提供机构:
MongoDB



