Quickest way to Install and run MongoDB in Windows 7, 8, 10 ™ - Duration: 7:53. SmartTech 7,894 views. For anyone that happens to try to create a mongodb service on Windows 8 and follows the instructions on MongoDB's website AND still is unable to create the service successfully - I've written this post that explains how I got it to work after experiencing problems trying to set the mongo service on my Windows 8 laptop.
The instructions/packages on the MongoDB site are currently available for LTS Ubuntu 12.04 and 14.04 only. The packages are set up to use upstart instead of systemd. You need to create a systemctl file to be ready for systemd. Create it by sudo nano /etc/systemd/system/mongodb.serviceIt will look like UnitDescription=High-performance, schema-free document-oriented databaseAfter=network.targetServiceUser=mongodbExecStart=/usr/bin/mongod -quiet -config /etc/mongod.confInstallWantedBy=multi-user.targetNow you can start the service and check its state by sudo systemctl start mongodbsudo systemctl status mongodband finally enable it permanently by sudo systemctl enable mongodb(Source: ).
Am running MongoDB 2.2 on Ubuntu and if I run: sudo mongodI get an error that it can't find /data/db, which is not where the database is. In mongod.conf the database path is specified as the Ubuntu 10gen default /var/lib/mongodb which is where the db is located. Seems like mongod is not finding the conf file. So when I run: sudo mongod -f /etc/mongodb.confThe server starts up fine and output is logged to the log file: /var/log/mongodb/mongodb.log. All is happy. I can switch to another shell, log into mongo shell, see the databases and run queries.So, I cancel out of that and try to run as a service: sudo status mongodbmongodb stop/waiting sudo start mongodbmongodb start/running, process 10468Looks good so far, but the mongo server did not start. Running another: sudo status mongodbmongodb stop/waiting mongoMongoDB shell version: 2.2.0connecting to: testSat Sep 1 19:07:43 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91exception: connect failed'test' is not the correct database, and nothing appears in the log file.I am at a loss as to what could be wrong.
I checked the upstart scripts and they seem fine. /etc/init/mongodb.conf runs: mongodb -exec /usr/bin/mongod - -config /etc/mongodb.conf. OK, this all comes down to permissions, but let's take it step by step.
![Service Mongodb Server Failed To Start For Liscad Installation Service Mongodb Server Failed To Start For Liscad Installation](/uploads/1/2/5/5/125515296/673403314.jpg)
When you run sudo mongod it does not load a config file at all, it literally starts with the compiled in defaults - port, of /data/db etc. that is why you got the error about not being able to find that folder. The 'Ubuntu default' is only used when you point it at the config file (if you start using the service command, this is done for you behind the scenes).Next you ran it like this: sudo mongod -f /etc/mongodb.confIf there weren't problems before, then there will be now - you have run the process, with your normal config (pointing at your usual dbpath and log) as the root user. That means that there are going to now be a number of files in that normal MongoDB folder with the user:group of root:root.This will cause errors when you try to start it as a normal service again, because the mongodb user (which the service will attempt to run as) will not have permission to access those root:root files, and most notably, it will probably not be able to write to the log file to give you any information.Therefore, to run it as a normal service, we need to fix those permissions. First, make sure MongoDB is not currently running as root, then: cd /var/log/mongodbsudo chown -R mongodb:mongodb.cd /var/lib/mongodbsudo chown -R mongodb:mongodb.That should fix it up (assuming the user:group is mongodb:mongodb), though it's probably best to verify with an ls -al or similar to be sure.
Once this is done you should be able to get the service to start successfully again. First confirm that the mongodb user/group has permission to write to both the data directory and log file:$ sudo chown -R mongodb:mongodb /var/lib/mongodb/.$ sudo chown -R mongodb:mongodb /var/log/mongodb.logStart up MongoDB as a Daemon (background process) using the following command:$ mongod -fork -dbpath /var/lib/mongodb/ -smallfiles -logpath/var/log/mongodb.log -logappendTo enter the Mongo CLI, access the admin and issue the shutdown command:$./mongo use admin db.shutdownServerRef. None of the above answers worked for me. I finally figured it out by debugging the init script with:sudo bash -x /etc/init.d/mongodb startAnd seeing it was passing the wrong config path to mongod. I simply changed the line in /etc/init.d/mongodb from 'CONF=/etc/mongodb.conf' to 'CONF=/etc/mongod.conf'.
Version 2 uses the former, and installing version 3 added /etc/mongod.conf with the new format but apparently did not update the init script.UPDATE: I now have a much stranger problem where the init script works, but only if I run it with 'sudo bash -x /etc/init.d/mongodb start' and not with 'sudo service mongodb start'. Same thing for stop.