Mongo index creation
diff --git a/libs/community/langchain_community/chat_message_histories/mongodb.py b/libs/community/langchain_community/chat_message_histories/mongodb.py
index bd65c4443cc113..f9e1e93db61fa0 100644
--- a/libs/community/langchain_community/chat_message_histories/mongodb.py
+++ b/libs/community/langchain_community/chat_message_histories/mongodb.py
@@ -30,6 +30,8 @@ class MongoDBChatMessageHistory(BaseChatMessageHistory):
             of a single chat session.
         database_name: name of the database to use
         collection_name: name of the collection to use
+        create_index: whether to create an index with name SessionId. Set to False if
+            such an index already exists.
     """
 
     def __init__(
@@ -38,6 +40,7 @@ def __init__(
         session_id: str,
         database_name: str = DEFAULT_DBNAME,
         collection_name: str = DEFAULT_COLLECTION_NAME,
+        create_index: bool = True,
     ):
         from pymongo import MongoClient, errors
 
@@ -53,7 +56,8 @@ def __init__(
 
         self.db = self.client[database_name]
         self.collection = self.db[collection_name]
-        self.collection.create_index("SessionId")
+        if create_index:
+            self.collection.create_index("SessionId")
 
     @property
     def messages(self) -> List[BaseMessage]:  # type: ignore

- [ ] Title: Mongodb: MongoDB connection performance improvement. 
- [ ] Message: 
    - **Description:** I made collection index_creation as optional. Index Creation is one time process.
    - **Issue:** MongoDBChatMessageHistory class object is attempting to create an index during connection, causing each request to take longer than usual. This should be optional with a parameter.
    - **Dependencies:** N/A
    - **Branch to be checked:** origin/mongo_index_creation

