Mongo shell closes immediately - mongodb

When I launch the mongo shell it closes immediately. There is no error. It was working fine (yesterday). My MongoDB server is running perfectly, and my application is connecting to it fine. I can't even launch the shell without connecting to a database:
C:\mongodb\bin> mongo --verbose
MongoDB shell version: 2.4.7
Fri Mar 27 10:35:38.425 versionArrayTest passed
connecting to: test
Fri Mar 27 10:35:38.472 creating new connection to:127.0.0.1:27017
Fri Mar 27 10:35:38.472 BackgroundJob starting: ConnectBG
Fri Mar 27 10:35:38.487 connected connection!
bye
Fri Mar 27 10:35:38.487 freeing 1 uncollected class mongo::DBClientCursor objects
Fri Mar 27 10:35:38.487 freeing 1 uncollected class mongo::DBClientWithCommands objects
Fri Mar 27 10:35:38.487 freeing 1 uncollected class mongo::BSONHolder objects
Similarly when connecting with no db:
C:\mongodb\bin> mongo --nodb --norc --verbose
MongoDB shell version: 2.4.7
Fri Mar 27 10:37:00.513 versionArrayTest passed
bye
Any and all thoughts on how to connect gratefully received.

As, mongod service has stopped; you need to go in the task manager-> Services Tab
-> search for MongoDB
-> Right click and click start.
You will find mongod shell is working as it was working previously.
I hope this helped!

Related

The command '/bin/sh -c service mongod start' return a non-zero code: 1 in docker

i'm trying to create a docker image run Mongodb on my Raspberry Pi 3+ with Raspbian buster. But when i build image and run container, mongodb doesn't auto start, so i add command RUN service mongod start then build image. Mongodb seems to be installed, i checked by service --status-all and mongodb listed but not started. Error come when docker try to start mongodb serive: The command '/bin/sh -c service mongod start' return a non-zero code: 1.
This is myDockerfile:
FROM cretzel/rpi-mongodb
WORKDIR /usr/src/mongodb
RUN chmod +x /var/lib/mongodb
RUN service mongod start
EXPOSE 27017
CMD ["mongod"]
I tried to fix this and be told that it doesn't have permission, so i add RUN chmod +x /var/lib/mongodb to my dockerfile but it don't work.
Can someone help?
---------------- Update from #Adiii's answer -----------------------------------
My new dockerfile:
FROM cretzel/rpi-mongodb
WORKDIR /usr/src/mongodb
COPY ./entrypoint.sh .
RUN chmod +x ./entrypoint.sh
VOLUME ./database /data/db
EXPOSE 27017
CMD ["mongod"]
entrypoint.sh
#!/bin/bash
service mongod start
exec "$#"
The change solved my error but mongodb service still cannot start. This is log file:
Starting database: mongodb failed!
db level locking enabled: 1
mongod --help for help and startup options
Mon Nov 11 16:31:15
Mon Nov 11 16:31:15 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Mon Nov 11 16:31:15
warning: some regex utf8 things will not work. pcre build doesn't have --enable-unicode-properties
Mon Nov 11 16:31:15 [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db/ 32-bit host=38271f34412b
Mon Nov 11 16:31:15 [initandlisten]
Mon Nov 11 16:31:15 [initandlisten] ** NOTE: This is a development version (2.1.1-pre-) of MongoDB.
Mon Nov 11 16:31:15 [initandlisten] ** Not recommended for production.
Mon Nov 11 16:31:15 [initandlisten]
Mon Nov 11 16:31:15 [initandlisten] ** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
Mon Nov 11 16:31:15 [initandlisten] ** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Mon Nov 11 16:31:15 [initandlisten] ** with --journal, the limit is lower
Mon Nov 11 16:31:15 [initandlisten]
Mon Nov 11 16:31:15 [initandlisten] db version v2.1.1-pre-, pdfile version 4.5
Mon Nov 11 16:31:15 [initandlisten] git version: 47fbbdceb21fc2b791d22db7f01792500647daa9
Mon Nov 11 16:31:15 [initandlisten] build info: Linux raspberrypi 3.2.27+ #102 PREEMPT Sat Sep 1 01:00:50 BST 2012 armv6l BOOST_LIB_VERSION=1_49
Mon Nov 11 16:31:15 [initandlisten] options: {}
Mon Nov 11 16:31:15 [initandlisten] waiting for connections on port 27017
Mon Nov 11 16:31:15 [websvr] admin web console waiting for connections on port 28017
Mon Nov 11 16:32:15 [clientcursormon] mem (MB) res:20 virt:83 mapped:0
I don't understand Docker so much, it don't show any error. Please help!
You should not start the process at RUN command, each run command run at a separate shell and RUN is for installation and configuration not to start the process. To start the process in the container you need to start the process at entrypoint or CMD.
also, the container needs a process to run in foreground so service will not work in case of the container. so
EXPOSE 27017
CMD ["mongod"]
This is enough to start the mongo process, if the container is up and running it's mean mongod process is running, you do not need to check the status using service --status-all. as soon as MongoDB process dies container will die automatically.
Will suggest to use offical mongo docker image.

MongoDB Illegal Instruction

When I type in "mongo" in terminal
it cannot run and shows up these thing
MongoDB shell version: 2.4.9
Illegal instruction (core dumped)
then nothing happen.
I install mongodb in arch linux.
I have create /data/db.
What kind of processor is this running on? There have been issues in the past with unimplemented instructions on some older processor architectures.
Can you use gdb to examine the core file, or start the mongo process under gdb and reproduce the problem, and determine
what is the illegal instruction that is being executed?
what is the stack backtrace at the point where the illegal instruction occurs?
have you started mongod --dbpath "db location" first? – Eugene P yesterday
Did you get MongoDB from your system package manager or somewhere else? – sudo_O yesterday
This sounds like corruption, new versions of the mongo shell should produce another error if the MongoDB server isn't reachable. – Sammaye yesterday
I have used mongod --dbpath /data/db.
I get mongodb from pacakge manager, i have tried to compile from source, it also same.
mongod --dbpath /data/db
Tue Feb 25 13:27:46.024
Tue Feb 25 13:27:46.027 warning: 32-bit servers don't have journaling enabled by default. Please use --journal if you want durability.
Tue Feb 25 13:27:46.032
Tue Feb 25 13:27:46.128 [initandlisten] MongoDB starting : pid=23705 port=27017 dbpath=/data/db 32-bit host=xeraph.hk
Tue Feb 25 13:27:46.129 [initandlisten]
Tue Feb 25 13:27:46.131 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary .
Tue Feb 25 13:27:46.133 [initandlisten] ** 32 bit builds are limited to le ss than 2GB of data (or less with --journal).
Tue Feb 25 13:27:46.134 [initandlisten] ** Note that journaling defaults t o off for 32 bit and is currently off.
Tue Feb 25 13:27:46.136 [initandlisten] ** See http://dochub.mongodb.org/c ore/32bit
Tue Feb 25 13:27:46.138 [initandlisten]
Tue Feb 25 13:27:46.139 [initandlisten] db version v2.4.9
Tue Feb 25 13:27:46.140 [initandlisten] git version: nogitversion
Tue Feb 25 13:27:46.141 [initandlisten] build info: Linux root-armv6-copy 3.4.76 -1-ARCH #1 SMP PREEMPT Wed Jan 15 15:31:14 MST 2014 armv7l BOOST_LIB_VERSION=1_5 5
Tue Feb 25 13:27:46.141 [initandlisten] allocator: system
Tue Feb 25 13:27:46.142 [initandlisten] options: { dbpath: "/data/db" }
Tue Feb 25 13:27:46.227 [websvr] admin web console waiting for connections on po rt 28017
Tue Feb 25 13:27:46.228 [initandlisten] waiting for connections on port 27017
The terminal pause there, then i login to another ssh terminal,
mongo
Also illegal instruction.

error during mongo db.shutdownServer()

I got the following error when I try to shutdown mongodb in my VM Ubuntu.
I am running 12.10 Ubuntu headless server.
The current Mongodb Shell Version is 2.0.6
use admin
switched to db admin
> db.shutdownServer()
Tue Dec 10 14:17:03 DBClientCursor::init call() failed
Tue Dec 10 14:17:03 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1
server should be down...
Tue Dec 10 14:17:03 trying reconnect to 127.0.0.1
Tue Dec 10 14:17:03 reconnect 127.0.0.1 ok
Tue Dec 10 14:17:03 Socket recv() errno:104 Connection reset by peer 127.0.0.1:27017
Tue Dec 10 14:17:03 SocketException: remote: 127.0.0.1:27017 error: 9001 socket exception [1] server [127.0.0.1:27017]
Tue Dec 10 14:17:03 DBClientCursor::init call() failed
Tue Dec 10 14:17:03 query failed : admin.$cmd { getlasterror: 1.0, w: 1.0 } to: 127.0.0.1
Tue Dec 10 14:17:03 Error: error doing query: failed shell/collection.js:151
What should I do?
My reason for trying to shut it down is because I want to update to mongo 2.2.
Please advise.
Although the messaging is confusing, this is actually expected behaviour if you shutdown via the mongo shell. Since you ran the db.shutdownServer() command through the mongo shell it can no longer connect to the server and this is essentially indicating the shell has been disconnected.
The mongo shell tries to automatically reconnect when you hit enter, which results in the messages like "trying to reconnect ...".
There is an open issue to improve this behaviour/messaging if you'd like to upvote/watch it: SERVER-5467.

Get output of mongo shell script

as a part of my mongoDB maintenance I'm running mongo shell and make it to load 2 scripts. The command I'm running looks like follows:
$MONGO_HOME/bin/mongo --verbose --port 27017 replSetConfig.js initializeReplicaSet.js
The output I got is:
MongoDB shell version: 2.2.3
Thu Mar 7 03:00:00 versionCmpTest passed
Thu Mar 7 03:00:00 versionArrayTest passed connecting to: 127.0.0.1:27017/test
Thu Mar 7 03:00:01 creating new connection to:127.0.0.1:27017
Thu Mar 7 03:00:01 BackgroundJob starting: ConnectBG
Thu Mar 7 03:00:01 connected connection!
loading file: js/replSet.config.js
loading file: js/initializeReplicaSet.js
I'm redirecting the output to a log file but I would like to see some output of the loaded scripts as well. I.e. the output which I see in the shell if I start it and call load("...") for the very same scripts. Is there a way how to capture the output?
Thanks
To add output of scripts you must use print() or printjson() statements otherwise MongoDB will remain quiet about any output of a script.

Starting mongodb cluster

I'm starting 3 mongod processes on 3 different machines and try to run the mongos process on the another machine that runs also the application server.
I'm getting this message:
~$ mongos --configdb mongo1:27017,mongo2:27017,mongo3:27017
Mon Sep 24 10:34:05 mongos db version v2.0.4, pdfile version 4.5 starting (--help for usage)
Mon Sep 24 10:34:05 git version: nogitversion
Mon Sep 24 10:34:05 build info: Linux yellow 2.6.24-29-server #1 SMP Tue Oct 11 15:57:27 UTC 2011 x86_64 BOOST_LIB_VERSION=1_46_1
Mon Sep 24 10:34:09 ERROR: config servers mongo1:27017 and mongo2:27017 differconfig servers mongo1:27017 and mongo2:27017 differconfig servers mongo1:27017 and mongo2:27017 differconfig servers mongo1:27017 and mongo2:27017 differconfig servers not in sync! config servers mongo1:27017 and mongo2:27017 differ
chunks: "d41d8cd98f00b204e9800998ecf8427e" EOO
EOO EOO
configServer startup check failed
I've deleted mongod.lock from all config servers and restarted mongod.
That solved the problem.
There are 2 ways it can be done,
1) clear the data folder and restart the server, it will start as usual without any error,
2) delete the mongod lock file and Use the --repair option.