Closed Daxcor69 closed 1 year ago
This example doesn't make sense
This will add srv (mongodb+srv//myhost:8080):
const { mongoExport } = require('mongoback');
const options = {
host: 'myhost',
port: 8080,
srv: true,
all: true
};
I am taking a look into that, thanks for the issue
I don't know typescript, but I would think a conditional here:
function getMongoConnectionUri(options: ConnectionOptions): string {
let uri = options.uri;
if (!uri) {
const protocol = options.srv ? 'mongodb+srv' : 'mongodb';
const host = Array.isArray(options.host)
? `${options.host.map(({ host, port }) => `${host}:${port}`, '').join(',')}`
: `${options.host ?? ''}:${options.port ?? ''}`;
const auth = options.username
? options.password
? `${options.username}:${options.password}@`
: `${options.username}@`
: '';
const opt = getOptionsString(options);
uri = `${protocol}://${auth}${host}${opt}`;
}
return uri;
}
to create a different protocol and host based on srv
Exactly, I did some commits referring this issue, this is the last one. Now I am fixing the github action that runs the tests, after that I can publish the new version and close the issue
wow thank you for doing this right away, that is really cool. thank you for the project it is really helpful.
Thanks! I was chilling right now, so I saw the notificaiton email, so no problem. If you like the project feel free to add a star
Hello,
I think there is still an issue with SRV and ports. Here is the output of the backup. You will see that it does indeed connect to Mongo Atlas service. Gets the first collection to export and the spinner goes and then after a timeout it errors out with an dns/tcp lookup. If you look it is still showing a port number.
foundry
⣯ products2023-02-09T20:39:24.806+0000 could not connect to server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: cluster0.<redacted>.mongodb.net:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp: lookup cluster0.<redacted>.mongodb.net: No address associated with hostname }, ] }
✖ products
Do you have the Uri from the log? (Of course without pwd)
not sure how to get that, but here is the options object
{
host: 'cluster0.<redacted>.mongodb.net',
replicaSetName: 'atlas-<redacted>-shard-0',
srv: true,
username: 'backup',
password: '<redacted>',
outDir: '/backup/2023-2-10-0-15-50',
authenticationDatabase: 'found',
authenticationMechanism: 'SCRAM-SHA-1',
ssl: true,
tlsInsecure: true,
all: true,
outType: 'flat',
readPreference: 'primary',
realtimeLog: true
}
Because it does connect on the initial part, it does NOT throw an error with the uri. Only after it times out on the export of the collection does it throw the error. Is there a way to print the fully constructed uri ?
You are right, the part regarding the first connection is different from the one in which the collections are exported (this)
Sorry to be a PIA, but I am glad that I was able to help make it better. ;) Never got to do that before. Thanks for the quick response.
No problem, I am happy that I fixed those bugs. Now the new version is released
Sorry same issue remains, Here is my package.json
{
"name": "mongo_job",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"mongoback": "^3.0.5",
"winston": "^3.8.2",
"winston-loki": "^6.0.6"
}
}
Here is the output
{
host: 'cluster0.redact.mongodb.net',
replicaSetName: 'atlas-redact-shard-0',
srv: true,
username: 'backup',
password: 'redact',
outDir: '/backup/2023-2-10-20-58-12',
authenticationDatabase: 'found',
authenticationMechanism: 'SCRAM-SHA-1',
ssl: true,
tlsInsecure: true,
all: true,
outType: 'flat',
readPreference: 'primary',
realtimeLog: true
}
foundry
⣯ products2023-02-10T20:58:43.214+0000 could not connect to server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: cluster0.redact.mongodb.net:27017, Type: Unknown, Last error: connection() error occurred during connection handshake: dial tcp: lookup cluster0.redact.mongodb.net: No address associated with hostname }, ] }
✖ products
⣽ messageswaitings^C2023-02-10T20:58:46.530+0000 signal 'interrupt' received; forcefully terminating
✖ messageswaitings
I uninstalled 3.0.4 and then installed 3.0.5. fyi
A note:
tlsInsecure
seems not to be in the available options. Could also be that it is an option of mongoexport added after that I developed the module and I could add it if needed, but actually I did not find it here.
Another note:
I do not know if there are other uses for that, but when there is srv
I think that replicaSetName
is not more needed. For what I know, srv
is a kind of shortcut that was added in order to not have to write all the hosts + the replica set name every time. On mongoatlas indeed it is suggested in the connection uri only when you select "Connect with my application" and select very old versions of mongo.
I think I solved the issue, until now I didn't try the mongoexport for real with mongo atlas:
I put this in the index.ts for trial:
async function main() {
await mongoExport({
host: 'xxx.xxx.mongodb.net',
// replicaSetName: 'atlas-redact-shard-0',
srv: true,
username: 'xxx',
password: 'xxx',
outDir: './backup/2023-2-10-20-58-12',
// authenticationDatabase: 'found',
// authenticationMechanism: AuthenticationMechanism.SCRAM_SHA_1,
ssl: true,
all: true,
outType: 'flat',
readPreference: 'primary',
realtimeLog: true,
log: ['command', 'base']
});
}
main();
To note that I added log: ['command']
as a good debug
To note that I removed replicaSetName
; it didn't seem useful along with srv
After that I noticed that srv
is usable only with --uri
and not with --host xxx --port xxx
Now if srv
is true, --uri
is used
I also tried with the replicaSet and the three hosts and worked
In case it does not work, I think that specifying directly the uri
could be a good solution, but please report me eventual errors
I think that now it will work
OK the changes you made did the trick. In your docs, there is this
sslAllowInvalidCertificates: Default value: false. Bypasses the validation checks for server certificates and allows the use of invalid certificates. When using the allowInvalidCertificates setting, MongoDB logs as a warning the use of the invalid certificate.
When I run this, I got a deprecation warning and was told to use tlsInsecure. It looks like I didn't need this for Atlas, however I could see someone needed this if they host their own with an unsigned cert.
Again thank you for your help. Brad
I found that here: https://www.mongodb.com/docs/database-tools/release-notes/database-tools-changelog/#100.2.0-changelog
But it seems like it's not documented
When SRV = true, the port designation should be disabled. If I leave port out of the config I get 27017, if I put undefined it puts the colon and no port number. If I put false then it puts :false.
Here is my options config:
Here is the error: