langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Connection with mongo db

Open nikhilkotiya opened this issue 1 year ago • 3 comments

Can you please help me with connecting my LangChain agent to a MongoDB database? I know that it's possible to directly connect to a SQL database using this resource https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html but I'm not sure if the same approach can be used with MongoDB. If it's not possible, could you suggest other ways to connect to MongoDB?

nikhilkotiya avatar Apr 23 '23 18:04 nikhilkotiya

Can you please help me with connecting my LangChain agent to a MongoDB database? I know that it's possible to directly connect to a SQL database using this resource https://python.langchain.com/en/latest/modules/agents/toolkits/examples/sql_database.html but I'm not sure if the same approach can be used with MongoDB. If it's not possible, could you suggest other ways to connect to MongoDB?

hi, have you found some solutions to connect to mongodb?

BriskyGates avatar May 23 '23 06:05 BriskyGates

Would also be interested. Any updates?

PaulDiTi avatar May 31 '23 18:05 PaulDiTi

what's more, the MySQL too

sknightq avatar Jun 02 '23 09:06 sknightq

Looking for same, bump.

doverradio avatar Jun 05 '23 15:06 doverradio

Found a "workaround": Have gpt translate the prompt to a mongodb pipeline and then just execute the pipeline that gpt provided.

I just used the normal OpenAI api and in the system message, provided my mongodb database schema and the format in which the model should respond (told it to respond with a dictionary that includes the pipeline and the name of the collection to execute the pipeline on).

I then provided it with some few-shot examples to understand more complex pipelines and get mapping between the collections right (e.g. with $lookup).

As gpt responds with a string, the response needs to be parsed with json.loads, such that the pipeline can be executed on the database.

The results are pretty good so far.

PaulDiTi avatar Jun 17 '23 09:06 PaulDiTi

Hello @nikhilkotiya have you found any solutions to connect to mongodb?

prameelareddi avatar Aug 10 '23 09:08 prameelareddi

@prameela1610 No, but there is an indirect solution for MongoDB where we save the data in JSON files and then pass it to LangChain.

nikhilkotiya avatar Aug 15 '23 05:08 nikhilkotiya

Thank you for your response @nikhilkotiya you said that json agent right ??? I need the DB connection only bec every time the data will update, If i am using json agent that time i get only past data so the reason i need the connection of mongoDB . If you find something helps to connect the DB please share me Thank you !!!!

prameelareddi avatar Aug 17 '23 04:08 prameelareddi

@prameela1610 you can use the sync of mongo db with sql and then use connection of sql. Bit complicated

nikhilkotiya avatar Aug 24 '23 14:08 nikhilkotiya

Hi @nikhilkotiya , we are University of Toronto students, we want to take this issue to work on for our assignment and we will make a PR for this issue.

Gisellew10 avatar Oct 16 '23 20:10 Gisellew10

Hi, @nikhilkotiya

I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you are seeking guidance on connecting a LangChain agent to a MongoDB database and have received several comments from other users offering potential solutions. Additionally, a group of University of Toronto students has expressed interest in working on the issue for an assignment and plans to make a pull request.

Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, please let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

dosubot[bot] avatar Feb 08 '24 16:02 dosubot[bot]