question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MongoError: command find|insert|update requires authentication

See original GitHub issue

Do you want to request a feature or report a bug? bug

What is the current behavior? Under high load, lots of errors appear in the console like this: MongoError: command find requires authentication with error code 13. I believe it is when a connection gets closed/times out and then reconnects we start seeing errors like this. It only ever happens under very high load with >200 requests/second executing ~4 queries per request.

MongoError: command find requires authentication
  File "/worker/node_modules/mongodb-core/lib/cursor.js", line 247, col 25, in queryCallback
    return callback(new MongoError(result.documents[0]), null);
  File "/worker/node_modules/mongodb-core/lib/connection/pool.js", line 531, col 18, in null.<anonymous>
    return cb(err, result);
  File "internal/process/next_tick.js", line 176, col 11, in process._tickCallback

MongoDB server is v4.0 (seen also on v3.6) running as a Docker container. The logs show no unauthorised errors related to these queries, only these unrelated ones:

root@ubuntu-s-8vcpu-32gb-lon1-01:~# docker logs mongodb | grep authorized
2018-08-10T10:13:42.389+0000 I ACCESS   [conn188] Unauthorized: not authorized on admin to execute command { getLog: "startupWarnings", $db: "admin" }
2018-08-10T10:13:42.677+0000 I ACCESS   [conn188] Unauthorized: not authorized on admin to execute command { replSetGetStatus: 1.0, forShell: 1.0, $db: "admin" }
2018-08-10T10:13:43.623+0000 I ACCESS   [conn188] Unauthorized: not authorized on nanowire to execute command { find: "system.users", filter: {}, $db: "nanowire" }

If the current behavior is a bug, please provide the steps to reproduce.

Connection is initialised like this:

import mongoose from 'mongoose';

mongoose.Promise = global.Promise;

const connectToMongoDB = () => {
  const opts = {
    keepAlive: true,
    keepAliveInitialDelay: 300000,
    socketTimeoutMS: 30000,
    poolSize: 50,
    reconnectTries: Number.MAX_VALUE,
    reconnectInterval: 500,
    autoReconnect: true,
  };

  return mongoose.connect('mongodb://user:password@mongodb:27017/nanowire', opts);
};

export default connectToMongoDB;

After that mongoose is just used as normal in an express app, executing 3 finds, 1 insert and 2 updates on every request.

What is the expected behavior?

No authentication errors should occur as only one database is used with the same credentials, there is definitely no mixing of credentials to different databases. This also only occurs at high load.

Please mention your node.js, mongoose and MongoDB version.

Node 9.11.2 Mongoose 5.2.7 MongoDB 4.0.0

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:17

github_iconTop GitHub Comments

2reactions
SankaDcommented, Oct 25, 2018

I’m also getting following error when connecting to MongoDb Atlas from Firebase functions. Only happens when the servers been idle for sometime. Then doesn’t work till I deploy functions again.

{ MongoError: command update requires authentication
    at /user_code/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:581:63
    at authenticateStragglers (/user_code/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:504:16)
    at Connection.messageHandler (/user_code/node_modules/mongoose/node_modules/mongodb-core/lib/connection/pool.js:540:5)
    at emitMessageHandler (/user_code/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:310:10)
    at TLSSocket.<anonymous> (/user_code/node_modules/mongoose/node_modules/mongodb-core/lib/connection/connection.js:453:17)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at TLSSocket.Readable.push (_stream_readable.js:134:10)
    at TLSWrap.onread (net.js:559:20)
  operationTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1540468510 },
  ok: 0,
  errmsg: 'command update requires authentication',
  code: 13,
  codeName: 'Unauthorized',
  '$clusterTime': 
   { clusterTime: Timestamp { _bsontype: 'Timestamp', low_: 1, high_: 1540468510 },
     signature: { hash: [Object], keyId: [Object] } },
  name: 'MongoError' }
1reaction
vkarpov15commented, Nov 4, 2018

Interesting. I have never tried mongoose with firebase functions, will check it out

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve 'command find requires authentication' using ...
1. How to connect from terminal and mongo: When you install MongoDB the authorization is disabled. So keep it like that for now....
Read more >
"Command find requires Authentication" despite having ...
I've enabled authentication in the mongodb settings. Set up the usernames with password with the roles of read and dbOwner of the target...
Read more >
MongoError: command find|insert|update requires authentication
I believe it is when a connection gets closed/times out and then reconnects we start seeing errors like this. It only ever happens...
Read more >
mongoerror: command find requires authentication - You.com
Create a root user in admin database: Type: mongod in a terminal to run db, and then in another terminal run command mongo...
Read more >
Command find requires authentication despite having ... - Reddit
I've installed the MongoDB in the Ubuntu VPS for my website. Usernames were set up, and it has the roles of "read" and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found