AuthenticationFailed MONGODB-CR credentials missing in the user document

Error Description: When you are using MongoDB 3.0 and decide to use MONGODB-CR as password authentification mechanism instead of the default SCRAM-SHA-1 (or maybe MONGODB-CR is not your choice but is your legacy PHP/Java/Ruby driver support), the new user you create don’t have MONGODB-CR credentials as expected:

use admin
db.system.users.findOne({user: “”admin”,”})
{
“_id” : “admin.admin”,
“user” : “admin”,
“db” : “admin”,
“credentials” : {
“SCRAM-SHA-1″ : {
“iterationCount” : 10000,
“salt” : “FPnmqmCI04KHJVZunfaI2Q==”,
“storedKey” : “i+jvORcFsnx6CXt0Bd924e2f804=”,
“serverKey” : “PQHG8nYYcJTjFEClqjFRZ8PTLTA=”
},
“MONGODB-CR” : “8aab8902fd862afad8064b73bd149d00″
},
“roles” : [
{
“role” : “userAdminAnyDatabase”,
“db” : “admin”
}
]
}

Cause: authSchemaVersion is set  to “5” and only SCRAM credentials will be generated in MongoDB 3.0:

use admin
db.system.version.find()
{ “_id” : “authSchema”, “currentVersion” : 5 }

Solution: Restart mongod/mongos while disable –auth, then change authSchemaVersion to “3” to support MONGODB-CR. See https://jira.mongodb.org/browse/SERVER-17459

use admin
db.system.version.update({ “_id” : “authSchema”},{$set: {“currentVersion” : 3} })

AuthenticationFailed MONGODB-CR credentials missing in the user document

MongoDB exception: can’t use localhost in repl set member names except when using it for all members

Error: When use rs.Add():

{
“errmsg” : “exception: can’t use localhost in repl set member names except when using it for all members”,
“code” : 13393,
“ok” : 0
}

Cause:

1. Your replica set is using localhost for it members and you are adding a new member with IP/hostname other than localhost

2. Your replica set is using IP/hostname for it members and you are adding a new member with localhost as hostname

Solution: Only use localhost for replica set members if you are sure that all mongod/mongos instance are on the same local machine. Otherwise, use hostname or IP.

MongoDB exception: can’t use localhost in repl set member names except when using it for all members

MongoDB couldn’t connect to new shard socket exception [CONNECT_ERROR]

Error: addShard() command returns error:

{
“ok” : 0,
“errmsg” : “couldn’t connect to new shard socket exception [CONNECT_ERROR] for replname/hostname:27017″
}

Cause:

1. hostname:27017 cannot be reached

2. if hostname:27017 can be reached, then your replica set [replname] configuration contains members with ‘localhost‘ as host name

Solution: Unless you  are running all mongod/mongos instances on the same machine, then you can use ‘localhost’ in rs.Add() command. Otherwise, use hostname instead of localhost in all rs.Add(), sh.addShard() command. Note that when adding a host itself to replcaset/shard an usable hostname should be present in /etc/hosts, or you will get this error:

{ “errmsg” : “couldn’t initiate : can’t find self in the replset config”, “ok” : 0 }

MongoDB couldn’t connect to new shard socket exception [CONNECT_ERROR]

Best size for swap partition in Linux

The old rule: Swap size should be twice of the RAM is only applicable in the old system when RAM is small (<1GB)

The new rule:
Swap = Equal RAM size (if RAM < 2GB)
Swap = 2GB size (if 2GB < RAM < 8GB)
Swap = 0.5 RAM size (if RAM > 8GB)

There is no benefit to put the swap size twice as RAM > 2GB since a system using up to mutiple GBs in swap memory should not be a good design for performance.

Best size for swap partition in Linux

MongoDB: replset couldn’t find a slave with id 1, not tracking

Error: replset couldn’t find a slave with id 1, not tracking

Causes: After removing and adding replica to MongoDB replica set using rs.add() and rs.remove(), the replica set member id’s don’t follow a continuous order from _id: 0, for example:

{
“_id” : “rs0″,
“version” : 1,
“members” : [
{
“_id” : 4,
“host” : “mongodb0.example.net:27017″
},
{
“_id” : 5,
“host” : “mongodb1.example.net:27017″
},
{
“_id” : 7,
“host” : “mongodb2.example.net:27017″
}
]
}

Solution: You can use rs.reconfig() to re-etablish the order:

var cfg = {
“_id” : “rs0″,
“version” : 1,
“members” : [
{
“_id” : 0,
“host” : “mongodb0.example.net:27017″
},
{
“_id” : 1,
“host” : “mongodb1.example.net:27017″
},
{
“_id” : 2,
“host” : “mongodb2.example.net:27017″
}
]
}
rs.reconfig(cfg);

MongoDB: replset couldn’t find a slave with id 1, not tracking