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

collection.find() exits without throwing any error when user not found #343

Open
adams-family opened this issue Jul 25, 2021 · 0 comments
Open

Comments

@adams-family
Copy link

I have the following code:

(async () => {
    try {
        const db = require('monk')(
            process.env.MONGO_USERNAME + ':' + 
            process.env.MONGO_PASSWORD + '@' + 
            process.env.MONGO_HOST + '/' + 
            process.env.MONGO_DB);
    
        console.log('STARTING...');
        
        const collection = db.get('collection')

        var result = await collection.find();
        
        console.log('OK')
        
    } catch (error) {
        console.log('ERROR:', error);
        
    } finally {
        console.log('FINALLY')
    }
})();

This is what happens when running nodemon test.js:

[nodemon] starting `node test.js`
STARTING...
[nodemon] clean exit - waiting for changes before restart

This is very strange because the code never hits either one of: OK or ERROR or FINALLY - therefore I suspect that monk.find has to do a process.exit(0) somewhere inside.

In mongo's log I can find that the user was not found:

mongo_1   | {"t":{"$date":"2021-07-25T09:04:24.208+00:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn34","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"mongo_user","authenticationDatabase":"database","remote":"172.19.0.3:56774","extraInfo":{},"error":"UserNotFound: Could not find user \"mongo_user\" for db \"database\""}}
mongo_1   | {"t":{"$date":"2021-07-25T09:04:24.212+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn33","msg":"Connection ended","attr":{"remote":"172.19.0.3:56772","connectionId":33,"connectionCount":1}}

However, should the code throw an exception in this case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant