mongo can not connect to mongodb server - mongodb

I just installed mongodb on windows 10.
The server part
$ mongod --auth --dbpath ./db/
2017-04-26T15:08:27.905+0800 I CONTROL [initandlisten] MongoDB starting : pid=244 port=27017 dbpath=./db 64-bit host=DESKTOP-NK0JQ4S
2017-04-26T15:08:27.906+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-04-26T15:08:27.907+0800 I CONTROL [initandlisten] db version v3.4.4
2017-04-26T15:08:27.907+0800 I CONTROL [initandlisten] git version: 888390515874a9debd1b6c5d36559ca86b44babd
2017-04-26T15:08:27.907+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips 22 Sep 2016
2017-04-26T15:08:27.908+0800 I CONTROL [initandlisten] allocator: tcmalloc
2017-04-26T15:08:27.908+0800 I CONTROL [initandlisten] modules: none
2017-04-26T15:08:27.909+0800 I CONTROL [initandlisten] build environment:
2017-04-26T15:08:27.909+0800 I CONTROL [initandlisten] distmod: 2008plus-ssl
2017-04-26T15:08:27.909+0800 I CONTROL [initandlisten] distarch: x86_64
2017-04-26T15:08:27.909+0800 I CONTROL [initandlisten] target_arch: x86_64
2017-04-26T15:08:27.910+0800 I CONTROL [initandlisten] options: { security: { authorization: "enabled" }, storage: { dbPath: "./db/" } }
2017-04-26T15:08:27.914+0800 I - [initandlisten] Detected data files in ./db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2017-04-26T15:08:27.915+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3525M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-04-26T15:08:28.795+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory './db/diagnostic.data'
2017-04-26T15:08:28.798+0800 I NETWORK [thread1] waiting for connections on port 27017
2017-04-26T15:08:34.860+0800 I NETWORK [thread1] connection accepted from 127.0.0.1:59658 #1 (1 connection now open)
The connection part
$ mongo
MongoDB shell version v3.4.4
connecting to: mongodb://127.0.0.1:27017
This just shows that it is connecting to MongoDB, but can not connect to the MongoDB server.

Related

How to fix mongodb Error: Network is unreachable

I get this error, when I try to connect to MongoDB
Error:
Network is unreachable.
Running mongod before mongo shell didn't help .
When I restart my computer it works!!!Anyway I get that error again, something like 30 minutes later.
This is output from cmd, when I run command mongod
C:\Program Files\MongoDB\Server\4.0\bin>mongod
2019-04-26T18:50:26.559+0400 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-04-26T18:50:26.562+0400 I CONTROL [initandlisten] MongoDB starting : pid=1092 port=27017 dbpath=C:\data\db\ 64-bit host=DESKTOP-47AK9D5
2019-04-26T18:50:26.562+0400 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2019-04-26T18:50:26.563+0400 I CONTROL [initandlisten] db version v4.0.7
2019-04-26T18:50:26.563+0400 I CONTROL [initandlisten] git version: 1b82c812a9c0bbf6dc79d5400de9ea99e6ffa025
2019-04-26T18:50:26.564+0400 I CONTROL [initandlisten] allocator: tcmalloc
2019-04-26T18:50:26.565+0400 I CONTROL [initandlisten] modules: none
2019-04-26T18:50:26.565+0400 I CONTROL [initandlisten] build environment:
2019-04-26T18:50:26.565+0400 I CONTROL [initandlisten] distmod: 2008plus-ssl
2019-04-26T18:50:26.566+0400 I CONTROL [initandlisten] distarch: x86_64
2019-04-26T18:50:26.566+0400 I CONTROL [initandlisten] target_arch: x86_64
2019-04-26T18:50:26.567+0400 I CONTROL [initandlisten] options: {}
2019-04-26T18:50:26.568+0400 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
2019-04-26T18:50:26.568+0400 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2019-04-26T18:50:26.568+0400 I CONTROL [initandlisten] now exiting
2019-04-26T18:50:26.568+0400 I CONTROL [initandlisten] shutting down with code:100
Edit: I found a problem. MongoDB Server turns off automatically. Just change service startup type to Manual.
MongoDB Server Properties

mongo: “exception: connect failed”

I am trying to connect to the mongo server, using the "mongo" command in the command prompt and this error is showing: "exception: connect failed"
Here is how I am trying to do it:
enter image description here
This is the mongodb.log
2018-03-27T14:00:19.299+0800 I CONTROL [main] ***** SERVER RESTARTED *****
2018-03-27T14:00:19.647+0800 I CONTROL [main] Trying to start Windows service 'MongoDB'
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] MongoDB starting : pid=10480 port=27017 dbpath=d:\mongodbData\db 64-bit host=DESKTOP-KEA31I3
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] db version v3.6.3
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips 22 Sep 2016
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] allocator: tcmalloc
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] modules: none
2018-03-27T14:00:19.648+0800 I CONTROL [initandlisten] build environment:
2018-03-27T14:00:19.649+0800 I CONTROL [initandlisten] distmod: 2008plus-ssl
2018-03-27T14:00:19.649+0800 I CONTROL [initandlisten] distarch: x86_64
2018-03-27T14:00:19.649+0800 I CONTROL [initandlisten] target_arch: x86_64
2018-03-27T14:00:19.649+0800 I CONTROL [initandlisten] options: { service: true, storage: { dbPath: "d:\mongodbData\db" }, systemLog: { destination: "file", logAppend: true, path: "d:\mongodbData\log\mongodb.log" } }
2018-03-27T14:00:19.651+0800 I - [initandlisten] Detected data files in d:\mongodbData\db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2018-03-27T14:00:19.651+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7632M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2018-03-27T14:00:19.834+0800 I STORAGE [initandlisten] WiredTiger message [1522130419:833660][10480:140722874245456], txn-recover: Main recovery loop: starting at 4/6272
2018-03-27T14:00:19.970+0800 I STORAGE [initandlisten] WiredTiger message [1522130419:970024][10480:140722874245456], txn-recover: Recovering log 4 through 5
2018-03-27T14:00:20.046+0800 I STORAGE [initandlisten] WiredTiger message [1522130420:46191][10480:140722874245456], txn-recover: Recovering log 5 through 5
2018-03-27T14:00:20.172+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.172+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-03-27T14:00:20.172+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-03-27T14:00:20.172+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.173+0800 I CONTROL [initandlisten] ** WARNING: The file system cache of this machine is configured to be greater than 40% of the total memory. This can lead to increased memory pressure and poor performance.
2018-03-27T14:00:20.174+0800 I CONTROL [initandlisten] See http://dochub.mongodb.org/core/wt-windows-system-file-cache
2018-03-27T14:00:20.174+0800 I CONTROL [initandlisten]
2018-03-27T14:00:20.402+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory 'd:/mongodbData/db/diagnostic.data'
2018-03-27T14:00:20.404+0800 I NETWORK [initandlisten] waiting for connections on port 27017
2018-03-27T14:00:20.404+0800 I STORAGE [initandlisten] Service running
Please help me. How to fix it
Run this following command :
sudo service mongodb stop
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongod restart
mongo

Can't set mongo as replica set

Hi I am trying to use mongo-connector for transport data from mongo db to elasticsearch. For that I need to set mongodb as replica set. So I run the mongodb first by executing mongod command and run mongod --replSet "rs0 command after that. But it showed me an error as below.
2017-10-03T21:16:46.571-0700 I CONTROL [initandlisten] MongoDB starting : pid=12180 port=27017 dbpath=C:\data\db\ 64-bit host=ME
2017-10-03T21:16:46.572-0700 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-10-03T21:16:46.572-0700 I CONTROL [initandlisten] db version v3.4.6
2017-10-03T21:16:46.572-0700 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2017-10-03T21:16:46.573-0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips 22 Sep 2016
2017-10-03T21:16:46.573-0700 I CONTROL [initandlisten] allocator: tcmalloc
2017-10-03T21:16:46.573-0700 I CONTROL [initandlisten] modules: none
2017-10-03T21:16:46.573-0700 I CONTROL [initandlisten] build environment:
2017-10-03T21:16:46.573-0700 I CONTROL [initandlisten] distmod: 2008plus-ssl
2017-10-03T21:16:46.574-0700 I CONTROL [initandlisten] distarch: x86_64
2017-10-03T21:16:46.574-0700 I CONTROL [initandlisten] target_arch: x86_64
2017-10-03T21:16:46.574-0700 I CONTROL [initandlisten] options: { replication: { replSet: "rs0" } }
2017-10-03T21:16:46.575-0700 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: C:\data\db\mongod.lock The process cannot access the file because it is being used by another process.. Is a mongod instance already running?, terminating
2017-10-03T21:16:46.575-0700 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-10-03T21:16:46.575-0700 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-10-03T21:16:46.575-0700 I CONTROL [initandlisten] now exiting
2017-10-03T21:16:46.576-0700 I CONTROL [initandlisten] shutting down with code:100
Just Run the command directly mongod --replSet "rs0", don't use mongod and then the replSet command.

Unable to start mongdb

2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] MongoDB starting : pid=5716 port=27017 dbpath=/data/db/ 64-bit host=localhost
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] db version v3.2.0
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] git version: 45d947729a0315accb6d4f15a6b06be6d9c19fe7
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] allocator: tcmalloc
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] modules: none
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] build environment:
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] distmod: ubuntu1404
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] distarch: x86_64
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] target_arch: x86_64
2017-05-11T12:03:49.700+0530 I CONTROL [initandlisten] options: { storage: { dbPath: "/data/db/" } }
2017-05-11T12:03:49.724+0530 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2017-05-11T12:03:49.724+0530 I - [initandlisten] Fatal Assertion 28578
2017-05-11T12:03:49.724+0530 I - [initandlisten]
***aborting after fassert() failure`enter code here`
I am not able to start Mongodb server i tried using service as well and using --dbpath as well i don't know what is the issue. i tried to delete journal files as well but that didn't work
Try to delete the file /tmp/mongodb-27017.sock manually and restart the process.
Have you tried starting it with Sudo from the terminal like so
sudo mongod
this will require your system username and password

Create admin user MongoDB not possible

When I am trying to follow the tutorial by typing
mongod --port 27017 --dbpath /data/db1
console responds with
C:\WINDOWS\system32>mongod --port 27017 --dbpath /data/db1
2017-03-03T14:43:54.019+0100 I CONTROL [initandlisten] MongoDB starting : pid=1776 port=27017 dbpath=/data/db1 64-bit host=Tim-V5
2017-03-03T14:43:54.020+0100 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2017-03-03T14:43:54.021+0100 I CONTROL [initandlisten] db version v3.4.2
2017-03-03T14:43:54.021+0100 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-03-03T14:43:54.022+0100 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1u-fips 22 Sep 2016
2017-03-03T14:43:54.023+0100 I CONTROL [initandlisten] allocator: tcmalloc
2017-03-03T14:43:54.023+0100 I CONTROL [initandlisten] modules: none
2017-03-03T14:43:54.023+0100 I CONTROL [initandlisten] build environment:
2017-03-03T14:43:54.023+0100 I CONTROL [initandlisten] distmod: 2008plus-ssl
2017-03-03T14:43:54.024+0100 I CONTROL [initandlisten] distarch: x86_64
2017-03-03T14:43:54.024+0100 I CONTROL [initandlisten] target_arch: x86_64
2017-03-03T14:43:54.025+0100 I CONTROL [initandlisten] options: { net: { port: 27017 }, storage: { dbPath: "/data/db1" } }
2017-03-03T14:43:54.025+0100 I STORAGE [initandlisten] exception in initAndListen: 29 Data directory /data/db1 not found., terminating
2017-03-03T14:43:54.026+0100 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-03-03T14:43:54.026+0100 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-03-03T14:43:54.027+0100 I CONTROL [initandlisten] now exiting
2017-03-03T14:43:54.027+0100 I CONTROL [initandlisten] shutting down with code:100
Even I already have created folder with
mkdir C:\data\db
and checked that it exists!
Following with
mongo --port 27017
It responds with
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017/
MongoDB server version: 3.4.2
Server has startup warnings:
2017-03-03T10:02:59.647+0100 I CONTROL [initandlisten]
2017-03-03T10:02:59.647+0100 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-03T10:02:59.647+0100 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-03-03T10:02:59.647+0100 I CONTROL [initandlisten]
I am using windows 10, how can I solve this? It's rather frustating