Connect to multiple mongo databases dynamically #64
-
I have a requirement to connect to multiple Mongo databases dynamically. Depending on the request parameters I have to connect to a different database each time. How to achieve this? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 3 replies
-
To have multiple connections you have to use the |
Beta Was this translation helpful? Give feedback.
-
how about multiple SQL (mysql,etc) connection. i don't see the similar method for the SQL. |
Beta Was this translation helpful? Give feedback.
-
@ace3 you can check this: https://github.com/gofr-dev/gofr/blob/development/pkg/datastore/db.go#L121 |
Beta Was this translation helpful? Give feedback.
-
ahh, i see. thank you. |
Beta Was this translation helpful? Give feedback.
-
i just tried the gofr. right now i declare the variable of the new SQL client in the main() function. |
Beta Was this translation helpful? Give feedback.
To have multiple connections you have to use the
datastore.GetNewMongoDB
function, it will give you the object with methods to the new database.Your existing connection will not be replaced by this.