Here is the scenario… there will be standard (one mandatory) connection to one db, in this db, there is a collection which has customer db details(username,pwd). On each API call, there’ll be orgId that is passed as request body. Based on the orgId input, we should be fetching the relevant customer db details from the initial db. Based on the db details acquired from the DB call, we should connect to that particular DB and perform CRUD operation on the particular collection
Can we achieve this using mongorepository and spring boot?
you can configure to connect to a particular database (and there are many ways to configure). Repository calls can query a collection based upon an input (supplied) parameter value.The query results can be used to perform further actions.
For example, you can configure connection to a particular database using AbstractMongoClientConfiguration class and use with MongoRepository.
What I am looking for right now is, not to go with mongoTemplate, and just using mongoRepository alone, just as we do with normal single connection mongodb where we have repository interface for one document.
To explain my problem more clearly, I obtain the connection to the 1stDB, from this DB I query for the particular collection to fetch customer db credentials and now using this details(mongodb credentials) I want to connect to that particular DB and then perform CRUD operation on the collections in that particular DB.
All this I want to achieve using mongoRepository way of spring boot application
You will be able to do that. Using the latest of the Spring Data MongoDB software as well as the MongoDB server, facilitates latest features as well as developer APIs.
The Spring Data MongoDB reference documentation has code samples for most of the usage scenarios - as in your case using the MongoRepository API for configuration and operations on the MongoDB server.
You can always lookup online for specific articles, post queries, etc., at your favorite websites.