Cannot connect with MongoDB - mongodb

I have problems with connecting with mongo.
me#the_host:~$ mongo
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017
2018-06-28T17:06:37.445+0200 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:251:13
#(connect):1:6
exception: connect failed
I went to /var/log/mongodb/mongod.log to see:
2018-06-28T17:16:11.763+0200 I COMMAND [initandlisten] Assigning UUID b237b94b-b3a3-4ba1-9c39-c87d6f3555db to collection local.startup_log
2018-06-28T17:16:11.764+0200 F STORAGE [initandlisten] Unable to start up mongod due to missing featureCompatibilityVersion document.
2018-06-28T17:16:11.764+0200 F STORAGE [initandlisten] Please run with --journalOptions 4 to recover the journal. Then run with --repair to restore the document.
2018-06-28T17:16:11.764+0200 F - [initandlisten] Fatal Assertion 40652 at src/mongo/db/repair_database_and_check_version.cpp 555
2018-06-28T17:16:11.764+0200 F - [initandlisten]
I executed mongod --journalOptions 4 and then mongod --repair but the error is still the same.
I have no idea what to do next..
Could anybody, who overcame this before, point me to proper direction?

Related

mongod and mongo both are not running, showing error, can anyone tell whats the problem

MongoDB shell version v4.4.1
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: No connection could be made because the target machine actively refused it. :
connect#src/mongo/shell/mongo.js:374:17
#(connect):2:6
exception: connect failed
exiting with code 1
I had the same problem. Try starting the mongo shell with:
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log
Details are in the mongoDB docs:
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x-tarball/

Unable to start mongod with one missing collection wt file

I have a working mongod instance (v3.2.21).
But suddenly it stopped working. When i run mongo command it is throwing me following error:
2019-06-04T13:52:41.725+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
When i checked log its showing:
2019-06-04T13:36:43.388+0000 E STORAGE [initandlisten] WiredTiger (2) [1559655403:388180][8404:0x7fb74e904c80], file:collection-1-1305830686620002691.wt, WT_SESSION.open_cursor: /mnt/volume-fra1-01//collection-1-1305830686620002691.wt: handle-open: open: No such file or directory
2019-06-04T13:36:43.388+0000 E STORAGE [initandlisten] no cursor for uri: table:collection-1-1305830686620002691
2019-06-04T13:36:43.388+0000 F - [initandlisten] Invalid access at address: 0x58
2019-06-04T13:36:43.398+0000 F - [initandlisten] Got signal: 11 (Segmentation fault).
The collection which was earlier there is now missing in data directory
I tried to use --repair but the process gets stop at this collection.
I have looked at various resources but couldn't figure out how to make it working? Is there way so that wiredtiger escape this collection?
MongoD 4.0.3 and newer has better repair facilities as per SERVER-19815.
One thing you can try:
Copy your original dbpath so if the attempt is not successful, you don't clobber your original data
Download the 4.0.3 binaries (or newer, currently the latest is 4.0.10)
mongod --repair using the 4.0.3 binaries to attempt to repair the copied dbpath
If the repair is successful, try to run the 3.2.21 binaries pointing to the repaired dbpath
Please note that this repair attempt is best-effort and there's no guarantee of success. Having an up-to-date backup is still recommended. You might also want to investigate how the dbpath is missing a file to begin with.

MongoDB installed correctly using Homebrew on Mac but typing "mongo" on the command line gives error: "exception: connect failed"

Mongo wont start on Mac.
Typed: "brew tap mongodb/brew" everything worked fine
Typed: "brew install mongodb-community#4.0" everything worked fine.
Typedy: "brew services start mongodb-community#4.0" everything worked fine.
When i type: "mongo"
I get the following error:
MongoDB shell version v4.0.9
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2019-05-14T17:06:06.551-0400 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:343:13
#(connect):2:6
exception: connect failed
When I type: "mongodb" I get the following error at the end of attempting to start:
2019-05-14T17:05:59.227-0400 I STORAGE [initandlisten] shutdown: removing fs lock...
2019-05-14T17:05:59.228-0400 I CONTROL [initandlisten] now exiting
2019-05-14T17:05:59.228-0400 I CONTROL [initandlisten] shutting down with code:62
Any ideas are appreciated.
Thank you,

Mongodb index built failed

I have a MongoDB with around 80k documents, each one is an entry with title, body_text, etc. I want to do FullTextSearch, for which reason I created a text index with the command:
db.getCollection('arquivo_entry').createIndex({title:"text",body_text:"text"},{ weights:{title:2,body_text:1}},{default_language:"portuguese"})
The index building failed because of it ran out of memory and it killed the job that had mongodb running. This is in the log:
2018-03-22T14:58:12.017+0000 I - [initandlisten] Index Build: 2500/86187 2%
2018-03-22T14:58:15.028+0000 I - [initandlisten] Index Build: 6900/86187 8%
2018-03-22T14:58:18.012+0000 I - [initandlisten] Index Build: 12400/86187 14%
2018-03-22T14:58:21.065+0000 I - [initandlisten] Index Build: 17300/86187 20%
2018-03-22T14:58:24.047+0000 I - [initandlisten] Index Build: 22500/86187 26%
2018-03-22T14:58:27.043+0000 I - [initandlisten] Index Build: 28600/86187 33%
2018-03-22T14:58:30.013+0000 I - [initandlisten] Index Build: 34000/86187 39%
2018-03-22T14:58:32.478+0000 F - [initandlisten] out of memory.
And the problem now is that I'm not able to delete the index and each time I try to launch the database it starts to rebuild the index automatically. Additionally, I'm not able to start a mongodb shell. It gives me the following error:
MongoDB shell version v3.6.3 connecting to: mongodb://127.0.0.1:27017
2018-03-22T15:08:38.688+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-03-22T15:08:38.688+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:251:13 #(connect):1:6
exception: connect failed
You can start the database with --noIndexBuildRetry option, drop the text index, and restart the database as usual.

How to restart/delete an instance of mongod?

This has been covered in other SO posts, but unfortunately those solutions are not working.
How does one restart/delete a mongod instance?
Entering
$ mongod
I get the following error:
2016-01-24T09:49:19.557-0500 I CONTROL [initandlisten] MongoDB starting : pid=43675 port=27017 dbpath=/data/db 64-bit host=NAME-MacBook-Pro.local
2016-01-24T09:49:19.558-0500 I CONTROL [initandlisten] db version v3.0.8
2016-01-24T09:49:19.558-0500 I CONTROL [initandlisten] git version: 83d8cc25e00e42856924d84e220fbe4a839e605d
2016-01-24T09:49:19.558-0500 I CONTROL [initandlisten] build info: Darwin NAME-MacBook-Pro.local 15.2.0 Darwin Kernel Version 15.2.0: Fri Nov 13 19:56:56 PST 2015; root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49
2016-01-24T09:49:19.558-0500 I CONTROL [initandlisten] allocator: system
2016-01-24T09:49:19.558-0500 I CONTROL [initandlisten] options: {}
2016-01-24T09:49:19.558-0500 E NETWORK [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
2016-01-24T09:49:19.558-0500 E NETWORK [initandlisten] addr already in use
2016-01-24T09:49:19.558-0500 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
2016-01-24T09:49:19.558-0500 I CONTROL [initandlisten] dbexit: rc: 100
I explicitly gave myself permissions with
sudo chown -R <USERNAME> /data/db
This didn't work.
I tried to remove the directory entirely
sudo rm -rf /data/db
and recreate it
mkdir -p /data/db
but unfortunately this doesn't work.
I thought the solution would be to remove the file /data/db/mongod.lock but it doesn't exist:
rm /data/db/mongod.lock
Anything else I should try?
EDIT: After running with the different port using mongod --port 12345, when I use use admin and then db.shutdownServer(), I get the following error:
2016-01-24T10:32:25.039-0500 I NETWORK trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-01-24T10:32:25.039-0500 I NETWORK reconnect 127.0.0.1:27017 (127.0.0.1) ok
2016-01-24T10:32:25.040-0500 I NETWORK DBClientCursor::init call() failed
server should be down...
EDIT 2:
Restarting the machine does nothing. I've tried to access the default port with mongod --port 27017, and then
> use admin
> db.shutdownServer()
I get the output:
2016-01-25T12:05:32.163-0500 I NETWORK DBClientCursor::init call() failed
server should be down...
2016-01-25T12:05:32.166-0500 I NETWORK trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2016-01-25T12:05:32.166-0500 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused
2016-01-25T12:05:32.166-0500 I NETWORK reconnect 127.0.0.1:27017 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
In the log it say:
2016-01-24T09:49:19.558-0500 E NETWORK [initandlisten] listen(): bind() failed errno:48 Address already in use for socket: 0.0.0.0:27017
2016-01-24T09:49:19.558-0500 E NETWORK [initandlisten] addr already in use
It means that the port is already in use either by another process or another mongo instance.
You should use another port for this instance.
Refer to this link