Sunday, November 10, 2013

MongoDB Couldn't connect to [127.0.0.1] couldn't connect to server 127.0.0.1:27017

Getting following exception while trying to import the data into MongoDB from a CSV file on a remote linux box.

>mongoimport -d EmpDatabase -c EmployeeRecords --type csv --file /var/lib/testuser/root/data/emp-datasheet.csv --headerline

Couldn't connect to [127.0.0.1] couldn't connect to server 127.0.0.1:27017

Solution:

This requires the host and port to be specified with mongoimport command:

--host <hostname><:port>

Example:

>mongoimport --host <<HOST>>:<<PORT>> -d EmpDatabase -c EmployeeRecords --type csv --file /var/lib/testuser/root/data/emp-datasheet.csv --headerline

3 comments:

  1. Another error for authentication:

    connected to: 127.0.0.130:27017
    assertion: 13106 nextSafe(): { $err: "not authorized for query on EmpDatabase.EmployeeRecords", code: 16550 }

    It requires DB credentials to passed with mongoimport command :
    --username <> --password <>

    >mongoimport --host 127.0.0.130:27017 --username <> --password <> -d EmpDatabase -c EmployeeRecords --type csv --file /var/lib/testuser/root/data/emp-datasheet.csv --headerline

    ReplyDelete