-
I am running mongodb via docker (not via cloud setup). Is it possible to setup uri with my local docker mongodb instance? https://docs.llamaindex.ai/en/stable/examples/vector_stores/MongoDBAtlasVectorSearch/?h=mongo_uri
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To set up the URI for your local Docker MongoDB instance, you need to modify the Assuming your local Docker MongoDB instance is running on the default port 27017, your export MONGODB_URI="mongodb://localhost:27017" You can then use this URI in your Python code to connect to your local MongoDB instance: from pymongo.mongo_client import MongoClient
uri = "mongodb://localhost:27017"
client = MongoClient(uri) # Create a new client and connect to the server
try:
client.admin.command("ping") # Send a ping to confirm a successful connection
print("Pinged your deployment. You successfully connected to MongoDB!")
except Exception as e:
print(e) In the context of using from pymongo.mongo_client import MongoClient
from llama_index.vector_stores.mongodb import MongoDBAtlasVectorSearch
from llama_index.storage import StorageContext
from llama_index.readers import SimpleDirectoryReader
from llama_index.indices import VectorStoreIndex
# Set up the MongoDB URI for your local Docker instance
mongo_uri = "mongodb://localhost:27017"
mongodb_client = MongoClient(mongo_uri)
# Create the MongoDBAtlasVectorSearch store
store = MongoDBAtlasVectorSearch(mongodb_client)
# Create the storage context
storage_context = StorageContext.from_defaults(vector_store=store)
# Read documents from a directory
uber_docs = SimpleDirectoryReader(input_files=["./data/10k/uber_2021.pdf"]).load_data()
# Create a vector store index
index = VectorStoreIndex.from_documents(uber_docs, storage_context=storage_context) Make sure to replace |
Beta Was this translation helpful? Give feedback.
To set up the URI for your local Docker MongoDB instance, you need to modify the
MONGODB_URI
environment variable to point to your local Docker MongoDB instance instead of a cloud setup.Assuming your local Docker MongoDB instance is running on the default port 27017, your
MONGODB_URI
would look something like this:You can then use this URI in your Python code to connect to your local MongoDB instance: