title: Mongo Authentication Error When Connecting to MMS ReplicaSet
body: <p>I deployed  and manage my MongoDB instances on the server using MongoDB Management Service (MMS) and I have deployed a replica set. I have also made sure that I added a user with the required permissions in the "Authorisation &amp; Users" tab as shown in the image below.</p>
  
  <p><img src="https://i.stack.imgur.com/6i2JO.png" alt="Authorisation &amp; Users"></p>
  
  <p>When I log into my server and run the command to check if the user has been added it shows that they have been authenticated because it returns 1.</p>
  
  <pre><code>$ use admin
  $ db.auth('mbdb', 'xxxx')
  $ 1
  </code></pre>
  
  <p>I have a node application that connects to mongodb using mongoose and this is the url format that I use to connect:</p>
  
  <pre><code>'url' : 'mongodb://mbdb:xxxx@localhost:27000/dbprod?replicaSet=ProdSet'
  </code></pre>
  
  <p>The issue that I am having is that when I start the Node application I get this error:</p>
  
  <pre><code>&gt; mobile-bulletin-node@0.0.1 start /var/TeamCity/buildAgent/work/d81f9c89b9a85a90
  &gt; node ./bin/www
  
  { [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }
  js-bson: Failed to load c++ bson extension, using pure JS version
  
  /var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:246
      throw message;      
            ^
  MongoError: auth failed
  at Object.toError (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/utils.js:114:11)
  at /var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1156:31
  at /var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/db.js:1890:9
  at Server.Base._callHandler (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/base.js:448:41)
  at /var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:481:18
  at MongoReply.parseBody (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
  at null.&lt;anonymous&gt; (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/server.js:439:20)
  at emit (events.js:95:17)
  at null.&lt;anonymous&gt; (/var/TeamCity/buildAgent/work/d81f9c89b9a85a90/node_modules/mongoose/node_modules/mongodb/lib/mongodb/connection/connection_pool.js:201:13)
  at emit (events.js:98:17)
  </code></pre>
  
  <p>I have also attached my requested logs from the server that retrieved from MMS. I can see an authentication error but all the changes that I make don't seem to alter this error.</p>
  
  <pre><code>2015-03-11T04:04:00.183-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42476 #6051 (6 connections now open)
  2015-03-11T04:04:00.194-0500 I ACCESS   [conn6051] Successfully authenticated as principal mms-automation on admin
  2015-03-11T04:04:00.697-0500 I NETWORK  [conn6049] end connection 159.8.163.164:42462 (5 connections now open)
  2015-03-11T04:04:00.697-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42477 #6052 (6 connections now open)
  2015-03-11T04:04:00.707-0500 I ACCESS   [conn6052] Successfully authenticated as principal __system on local
  2015-03-11T04:04:03.158-0500 I ACCESS   [conn19] Successfully authenticated as principal mms-monitoring-agent on admin
  2015-03-11T04:04:04.695-0500 I NETWORK  [conn6050] end connection 159.8.163.164:42468 (5 connections now open)
  2015-03-11T04:04:04.695-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42486 #6053 (6 connections now open)
  2015-03-11T04:04:04.705-0500 I ACCESS   [conn6053] Successfully authenticated as principal __system on local
  2015-03-11T04:04:05.184-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42487 #6054 (7 connections now open)
  2015-03-11T04:04:25.811-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49873 #6055 (8 connections now open)
  2015-03-11T04:04:25.811-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49874 #6056 (9 connections now open)
  2015-03-11T04:04:25.812-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49875 #6057 (10 connections now open)
  2015-03-11T04:04:25.812-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49876 #6058 (11 connections now open)
  2015-03-11T04:04:25.812-0500 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:49877 #6059 (12 connections now open)
  2015-03-11T04:04:25.818-0500 I ACCESS   [conn6055]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
  2015-03-11T04:04:25.818-0500 I ACCESS   [conn6056]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
  2015-03-11T04:04:25.819-0500 I ACCESS   [conn6055] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
  2015-03-11T04:04:25.819-0500 I ACCESS   [conn6057]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
  2015-03-11T04:04:25.819-0500 I ACCESS   [conn6058]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
  2015-03-11T04:04:25.819-0500 I ACCESS   [conn6056] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
  2015-03-11T04:04:25.819-0500 I ACCESS   [conn6059]  authenticate db: dbprod { authenticate: 1, user: "mbdb", nonce: "xxx", key: "xxx" }
  2015-03-11T04:04:25.819-0500 I ACCESS   [conn6057] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
  2015-03-11T04:04:25.819-0500 I ACCESS   [conn6058] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
  2015-03-11T04:04:25.819-0500 I ACCESS   [conn6059] Failed to authenticate mbdb@dbprod with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document
  2015-03-11T04:04:25.823-0500 I NETWORK  [conn6059] end connection 127.0.0.1:49877 (11 connections now open)
  2015-03-11T04:04:25.823-0500 I NETWORK  [conn6058] end connection 127.0.0.1:49876 (11 connections now open)
  2015-03-11T04:04:25.823-0500 I NETWORK  [conn6056] end connection 127.0.0.1:49874 (11 connections now open)
  2015-03-11T04:04:25.823-0500 I NETWORK  [conn6057] end connection 127.0.0.1:49875 (11 connections now open)
  2015-03-11T04:04:25.823-0500 I NETWORK  [conn6055] end connection 127.0.0.1:49873 (7 connections now open)
  2015-03-11T04:04:30.710-0500 I NETWORK  [conn6052] end connection 159.8.163.164:42477 (6 connections now open)
  2015-03-11T04:04:30.710-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42495 #6060 (7 connections now open)
  2015-03-11T04:04:30.720-0500 I ACCESS   [conn6060] Successfully authenticated as principal __system on local
  2015-03-11T04:04:34.707-0500 I NETWORK  [conn6053] end connection 159.8.163.164:42486 (6 connections now open)
  2015-03-11T04:04:34.707-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42501 #6061 (7 connections now open)
  2015-03-11T04:04:34.717-0500 I ACCESS   [conn6061] Successfully authenticated as principal __system on local
  2015-03-11T04:04:54.412-0500 I ACCESS   [conn19] Successfully authenticated as principal mms-monitoring-agent on admin
  2015-03-11T04:04:54.414-0500 I QUERY    [conn19] assertion 13 not authorized for query on local.oplog.rs ns:local.oplog.rs query:{ $query: {}, $orderby: { $natural: 1 } }
  2015-03-11T04:04:54.414-0500 I QUERY    [conn19]  ntoskip:0 ntoreturn:-1
  2015-03-11T04:04:54.414-0500 I QUERY    [conn19] assertion 13 not authorized for query on local.oplog.rs ns:local.oplog.rs query:{ $query: {}, $orderby: { $natural: -1 } }
  2015-03-11T04:04:54.414-0500 I QUERY    [conn19]  ntoskip:0 ntoreturn:-1
  2015-03-11T04:05:00.724-0500 I NETWORK  [conn6060] end connection 159.8.163.164:42495 (6 connections now open)
  2015-03-11T04:05:00.724-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42512 #6062 (7 connections now open)
  2015-03-11T04:05:00.734-0500 I ACCESS   [conn6062] Successfully authenticated as principal __system on local
  2015-03-11T04:05:04.718-0500 I NETWORK  [conn6061] end connection 159.8.163.164:42501 (6 connections now open)
  2015-03-11T04:05:04.718-0500 I NETWORK  [initandlisten] connection accepted from 159.8.163.164:42517 #6063 (7 connections now open)
  2015-03-11T04:05:04.728-0500 I ACCESS   [conn6063] Successfully authenticated as principal __system on local
  </code></pre>
  
  <p>I have deployed and connected to a mongodb database with an instance that I was managing myself without mms so I have a feeling that I am missing or have left out to allow me to connect to a mongodb instance managed by mms.</p>
  
  <p>My automation agent, backup agent and monitoring agent are healthy too.</p>