Category: errors

  • 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 couldn’t initiate : can’t find self in the replset config

    Error: When use coomand rs.initiate()

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

    Cause: a hostname(s) of a replica set member(s) cannot be resolved

    Solution: Add hostname(s) in /etc/hosts

  • 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 }

  • Centos yum [Errno 12] Timeout:

    1. Clean up yum db:

    sudo rm -f /var/lib/rpm/__db*
    sudo rpmdb -vv –rebuilddb

    2. If the problem persists, check your proxy config:

    sudo grep ‘proxy’ /etc/yum.conf

    Note that the proxy config should be present in yum.conf, even if you already set a value for http_proxy

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

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

    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 on Windows: getnameinfo errno 10106

    Error: When starting the MongoDB service in the prompt (c:mongodbbinmongod.exe), I get the following error:

    exception in initAndListen:13082 getnameinfo error errno:10106
    The requested service provider could not be loaded or initialized.. terminating

    Cause: This is a WinSock error as in the mongod.log

    WSAEPROVIDERFAILEDINIT [10106]: Service provider failed to initialize. This error is returned if either a service provider’s DLL could not be loaded (LoadLibrary failed) or the provider’s WSPStartup or NSPStartup function failed.

    Solution: open cmd as admin, type the following and hit Enter to repair winsock.

    netsh winsock reset

  • MongoDB Exception: aggregation result exceeds maximum document size (16MB)

    MongoDB aggregation result exceeds maximum document size (16MB)

    {
    “errmsg” : “exception: aggregation result exceeds maximum document size (16MB)”,
    “code” : 16389,
    “ok” : 0
    }

    Cause:

    • You are using MongoDB version <=2.4
    • You are using MongoDB version >=2.6 but are using a mongo shell 2.4 or a PHP/C/Java/Ruby driver to run aggregate() without specifying the output as “cursor”

    Solution for 2.4: Limit the output using $skip and $limit to fit the 16MB limit

    Solution for 2.6:

    Java driver: Use option:

    .newAggregationOptions().outputMode(
    AggregationOptions.OutputMode.CURSOR).build()

    PHP driver:

    public MongoCommandCursor MongoCollection::aggregateCursor ( array $command [, array $options ] )

  • Unclean shutdown detected when using mongodb docker

    When stopping a docker with mongod daemon running using command:

    docker stop <container_id>

    the next time you start the mongod docker, it will complain about unclean shutdown detected:

    “Unclean shutdown detected.
    Please visit http://dochub.mongodb.org/core/repair for recovery
    instructions.”

    Cause: “docker stop” use SIGTERM to kill mongod daemon, while it is recommended to use SIGINT

    Solution:

    docker kill -s INT <container_id>

  • Phantomjs error: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file

    Error: When running phantomjs command:

    error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory

    Cause: Missing libfontconfig.so.1

    Solution:

    Centos:

    sudo yum install fontconfig

    Ubuntu:

    sudo apt-get install libfontconfig1

  • Ruby on Rails error: Both value and block given (FactoryGirl::AttributeDefinitionError)

    Error: When using a callback like after(:create) or before(:create), Ruby raises this error:

    Both value and block given (FactoryGirl::AttributeDefinitionError)

    Cause: These callback syntaxes are supported from factory_girl 3.3.0 or above.

    Solution:

    Change after(:create) to after_create and before(:create) to before_create

    Or Upgrade factory_girl to version >=3.3.0