-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Specify connection config via an object and not string #10339
Comments
Do you mean how is it possible to not use a string or specify the connection string with an object instead of a string? |
Yeah, pretty much exactly like in my example |
So there is no native way to do this with mongoose. You could save each part as a variable and concatenate them to achieve a similar effect. |
😳 Wow, I'm baffled that this is not supported yet.
|
I mean to be fair though, this isn't that hard to implement. My current setup is just get the config, and generate a link using a config const conf:{
mongodb: {
username: string,
password: string,
ip: string,
db: string,
port: string
}
} = configFunction()
const MongoDBendPoint = "mongodb://" + conf.mongodb.username + ":" + conf.mongodb.password + "@" + conf.mongodb.ip + ":" + conf.mongodb.port + "/" + conf.mongodb.db + "?readPreference=primary&appname=MyAppNameHere&ssl=false?authSource=" + conf.mongodb.db
//or
const MongoDBendPoint2 = `mongodb://${conf.mongodb.username}:${conf.mongodb.password}@${conf.mongodb.ip}:${conf.mongodb.port}/${conf.mongodb.db}?readPreference=primary&appname=MyAppNameHere&ssl=false?authSource=${conf.mongodb.db}` |
What not simply add the function to build this string to mongoose? Including type / range checking, normalization, and so on. |
I'm not saying it's a perfect solution, I'm just saying that it could be a workaround-ish solution, for now. I'm very not against having this function be in mongoose |
Not a bad idea. The only potential downside is that connection string is MongoDB's default approach, so makes it harder to copy/paste connection string from Atlas or Studio 3T. But worth considering for the future. |
Wait, are you suggesting to replace it completely? |
Well I don't 😳 |
@ShadiestGoat not suggesting replacing it completely, that would be too big a breaking change for too little benefit IMO. But a named parameters style syntax for |
Yeah, I no sorry I was a bit worried that you were going to replace it completely, I don't see any benefits to that personally. The connect should be |
Actually, on second thought, I think it would be cleaner to have two functions:
|
Sure, |
Sorry if I'm blind, but how can I specify the connection with an object and not a string? E.g.
The text was updated successfully, but these errors were encountered: