Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Configuration for Multiple MongoDB Connections #457

Open
Nikitas-io opened this issue Apr 5, 2022 · 4 comments
Open

Dynamic Configuration for Multiple MongoDB Connections #457

Nikitas-io opened this issue Apr 5, 2022 · 4 comments
Labels
enhancement A viable proposal of a new feature for the module

Comments

@Nikitas-io
Copy link

Nikitas-io commented Apr 5, 2022

Feature Request

So I'm using MongoDB Atlas, Mongoose, Multer, and GridFsStorage to upload files to a single database on the cloud which works fine, but I want to be able to upload files to different databases, using different database connections dynamically.

In order to do this, I want to set up my Multer GridFsStorage configuration so that the "db" field changes dynamically based on the API request. However, I can't access the HTTP request in the "db" field, which would make it impossible for me to change the DB connection dynamically and it seems to me that it is not currently possible do this.

The solution I'd like to see

I would like to see a way to make the GridFsStorage configuration work dynamically with multiple DB connections.
Ideally, the "db" field in the GridFsStorage configuration would be able to function like the "file" field where the request is accessible through the parameters of a function:

const storage = new GridFsStorage({
    
    // I want to be able to access the request through a function's paramaters. That way I'll be able to return  
    // the database connection back to the "db" field dynamically based on the request's cookies.
    db: (req) => {
          // Determine the DB connection dynamically using the req parameter.
          dynamicConnection = connectionFactory.getDatabaseConnection(req.cookies.dbName);

          // Return the DB connection back to the db field.
          return dynamicConnection;
    }
    
    // The fact that I have access to the user's HTTP request in this method is excellent.
    file: (req, file) => { 
          ...
    }
});


const fileUpload = multer({ 
    // Set the storage strategy.
    storage: storage,

    limits: { fileSize: 1024 * 1024 * 2 },
    fileFilter: fileFilter,
});
@Nikitas-io Nikitas-io added the enhancement A viable proposal of a new feature for the module label Apr 5, 2022
@Nikitas-io Nikitas-io changed the title Multer GridFsStorage Dynamic Configuration for Multiple MongoDB Connections Dynamic Configuration for Multiple MongoDB Connections Apr 5, 2022
@devconcept
Copy link
Owner

This is very interesting indeed and I think I have enough material for a new major release. I'll start working on it and see what I can come up with.

@Nikitas-io
Copy link
Author

Thank you so much for your interest in the issue! I posted a question about this problem on Stack Overflow before opening this issue and given the fact that it got some upvotes it seems to me that other people would find this feature usefull as well ❤️‍🔥

@PanagosAlex
Copy link

Any updates on this issue yet??? 🕵️

@Alokpoddar110
Copy link

please provide solution for this waiting or let us know how much time it will take , thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A viable proposal of a new feature for the module
Projects
None yet
Development

No branches or pull requests

4 participants