以下是我的mongo.conf

# mongod.conf

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true

systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

net:
  port: 27017
#  bindIp: 127.0.0.1

replication:
  replSetName: rs0
  oplogSizeMB: 250

我试图使用
wget https://raw.githubusercontent.com/mongodb/docs-assets/primer-dataset/dataset.json
mongoimport --host=127.0.0.1 --port=27017 --db test --collection dataset --file dataset.json

并在主机(mac)上进行了尝试:
mongoimport --host=127.0.0.1 --port=27071 --db test --collection dataset --file dataset.json

在这两种情况下,我都得到以下输出:
2016-02-25T11:01:56.280-0500    connected to: 127.0.0.1:27071
2016-02-25T11:01:59.278-0500    [........................] test.dataset 0.0 B/11.3 MB (0.0%)
2016-02-25T11:01:59.309-0500    [........................] test.dataset 0.0 B/11.3 MB (0.0%)
2016-02-25T11:01:59.309-0500    Failed: error checking connected node type: no reachable servers
2016-02-25T11:01:59.309-0500    imported 0 documents

我对主机系统上的27071端口的所有请求都被转发到linux客户机上的post 27017。没有连接问题,因为curl localhost:27071给出It looks like you are trying to access MongoDB over HTTP on the native driver port
更新:
以下是mongo的日志:
2016-02-25T18:33:23.938+0000 I CONTROL  ***** SERVER RESTARTED *****
2016-02-25T18:33:23.941+0000 I CONTROL  [initandlisten] MongoDB starting : pid=4810 port=27017 dbpath=/var/lib/mongodb 64-bit host=vagrant-ubuntu-trusty-64
2016-02-25T18:33:23.941+0000 I CONTROL  [initandlisten] db version v3.0.9
2016-02-25T18:33:23.941+0000 I CONTROL  [initandlisten] git version: 20d60d3491908f1ae252fe452300de3978a040c7
2016-02-25T18:33:23.941+0000 I CONTROL  [initandlisten] build info: Linux ip-10-732-9-221 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2016-02-25T18:33:23.941+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2016-02-25T18:33:23.941+0000 I CONTROL  [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "0.0.0.0", port: 27017 }, replication: { oplogSizeMB: 250, replSetName: "rs0" }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-02-25T18:33:23.969+0000 I JOURNAL  [initandlisten] journal dir=/var/lib/mongodb/journal
2016-02-25T18:33:23.969+0000 I JOURNAL  [initandlisten] recover : no journal files present, no recovery needed
2016-02-25T18:33:24.006+0000 I JOURNAL  [durability] Durability thread started
2016-02-25T18:33:24.006+0000 I JOURNAL  [journal writer] Journal writer thread started
2016-02-25T18:33:24.007+0000 I CONTROL  [initandlisten]
2016-02-25T18:33:24.007+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-02-25T18:33:24.007+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-02-25T18:33:24.007+0000 I CONTROL  [initandlisten]
2016-02-25T18:33:24.007+0000 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-02-25T18:33:24.007+0000 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2016-02-25T18:33:24.007+0000 I CONTROL  [initandlisten]
2016-02-25T18:33:24.010+0000 I REPL     [initandlisten] Did not find local replica set configuration document at startup;  NoMatchingDocument Did not find replica set configuration document in local.system.replset
2016-02-25T18:33:24.011+0000 I NETWORK  [initandlisten] waiting for connections on port 27017

如果尝试从主机系统执行mongoimport --host=0.0.0.0 --port=27071 --db test --collection dataset --file dataset.json,则会将以下内容添加到日志中:
2016-02-25T18:36:03.443+0000 I NETWORK  [initandlisten] connection accepted from 10.0.2.2:51277 #1 (1 connection now open)
2016-02-25T18:36:06.479+0000 I NETWORK  [conn1] end connection 10.0.2.2:51277 (0 connections now open)

当我在来宾linux上尝试同样的命令时,我得到:
2016-02-25T18:38:29.982+0000 I NETWORK  [initandlisten] connection accepted from 127.0.0.1:59910 #2 (1 connection now open)
2016-02-25T18:38:32.994+0000 I NETWORK  [conn2] end connection 127.0.0.1:59910 (0 connections now open)

最佳答案

尝试将bindIp参数设为0.0.0.0,然后重新启动服务。

07-24 09:34