mirror of
https://github.com/hwchase17/langchain.git
synced 2025-11-24 18:19:00 +00:00
# Add MongoDB storage
- **Description:**
Add MongoDB Storage as an option for large doc store.
Example usage:
```Python
# Instantiate the MongodbStore with a MongoDB connection
from langchain.storage import MongodbStore
mongo_conn_str = "mongodb://localhost:27017/"
mongodb_store = MongodbStore(mongo_conn_str, db_name="test-db",
collection_name="test-collection")
# Set values for keys
doc1 = Document(page_content='test1')
doc2 = Document(page_content='test2')
mongodb_store.mset([("key1", doc1), ("key2", doc2)])
# Get values for keys
values = mongodb_store.mget(["key1", "key2"])
# [doc1, doc2]
# Iterate over keys
for key in mongodb_store.yield_keys():
print(key)
# Delete keys
mongodb_store.mdelete(["key1", "key2"])
```
- **Dependencies:**
Use `mongomock` for integration test.
---------
Co-authored-by: Bagatur <baskaryan@gmail.com>
Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com>
12 lines
334 B
Python
12 lines
334 B
Python
"""Light weight unit test that attempts to import MongodbStore.
|
|
|
|
The actual code is tested in integration tests.
|
|
|
|
This test is intended to catch errors in the import process.
|
|
"""
|
|
|
|
|
|
def test_import_storage() -> None:
|
|
"""Attempt to import storage modules."""
|
|
from langchain_community.storage.mongodb import MongoDBStore # noqa
|