Error while installing MongoDB as windows service - mongodb

I tried installing MongoDB 3. X version as windows service. I executed following commands:
mkdir c:\data\db
mkdir c:\data\log
echo logpath=c:\data\log\mongod.log> "C:\mongodb\mongod.cfg"
echo dbpath=c:\data\db>> "C:\mongodb\mongod.cfg"
sc.exe create MongoDB binPath= "\"C:\mongodb\bin\mongod.exe\" --service --config=\"C:\mongodb\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
after executing these commands I got following message:
[SC] CreateService SUCCESS
But I was unable to start the windows service. Everytime, I tried installing MongoDB as windows service, it threw some error.
Then I followed this post: but I am still getting errors.
Please see below image for more information.
Event log under System is showing following error: The MongoDB service terminated with service-specific error Cannot create another system semaphore..
Earlier I had installed MongoDB v 2.6 & I was able to install it successfully as windows service. I wonder if I need a different approach to install version 3.X.

I have now installed mongodb 2.6. and followed these instructions.
I suggest extracting the Mongo installation to c:\mongodb.
Create the c:\mongodb\logs and the c:\mongodb\data\db directories.
Then browse the the c:\mongodb\bin directory and run the following to remove the service (if you've installed it!):
mongod --remove
Then install the service, specifying the log and data directories:
mongod --logpath c:\mongodb\logs\mongo.log --dbpath c:\mongodb\data\db --directoryperdb --install

I resolved this by removing mongod.lock and storage.bson files under /data/db.

Related

getting error while connecting to mongo.exe [duplicate]

I'm trying to run Mongo from the Command-Line:
What's wrong? (I've IIS on localhost:80). And Apache on port 8080. Are there any issues
with this?
C:\MONGO\Project1\mongo\bin>mongo --port 27017
MongoDB shell version: 2.0.3
connecting to: 127.0.0.1:27017/test
Sat Mar 10 16:16:45 Error: couldn't connect to server 127.0.0.1:27017 shell/mong
o.js:86
exception: connect failed
I found that when I got this error it wasn't because I didn't have my default db path set up. It was because I was trying to run mongo.exe before running mongod.exe.
Did you create the default db path?
It defaults to "/data/db directory (or c:\data\db on Windows)"
Source: http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo
As Admin, create directory:
mkdir c:\mongo\data\db
As Admin, install service:
.\mongod.exe --install --logpath c:\mongo\logs --logappend --bind_ip 127.0.0.1 --dbpath c:\mongo\data\db --directoryperdb
Start MongoDB:
net start MongoDB
Start Mongo Shell:
c:\mongo\bin\mongo.exe
Follow
Create default db folder.
c:\data\db
and also log folder
c:\data\log\mongo.log
or use following commands in command-prompt
mkdir c:\data\log
mkdir c:\data\db
Create config file in bin folder of mongo (or you may in save your desired destination).
Add following in text file named "mongod" and save it as
mongod.cfg
dbpath=c:\data\db
logpath=c:\data\log\mongo.log
or use following commands in command-prompt
echo dbpath=c:\data\db>> "mongod.cfg"
echo logpath=c:\data\log\mongo.log>> "mongod.cfg"
Now open command-prompt (administrator) and run the following command to start mongo server
mongod
Open another command-prompt (don't close 1st prompt) and run client command:
mongo
Hope this will help or you have done this already.
The error occurs when trying to run mongo.exe WITHOUT having executed mongod.exe.
The following batch script solved the problem:
#echo off
cd C:\mongodb\bin\
start mongod.exe
start mongo.exe
exit
If you are getting these type of errors when running mongod from command line or running mongodb server,
then follow these steps,
Create db and log directories in C: drive
C:/data/db and C:data/log
Create an empty log file in log dir named mongo.log
Run mongod from command line to run the mongodb server or create a batch file on desktop which can run the mongod.exe file from your mongodb installation direction. That way you just have to click the batch file from your desktop and mongodb will start.
If you have 32-bit system, try using --journal with mongod command.
Create default db folder.
c:\data\db
and also log folder
c:\data\log\mongo.log
or use following commands in command-prompt
mkdir c:\data\log
mkdir c:\data\db
you can use below command,
mongod --dbpath=D:\home\mongodata
where D:\home\mongodata is the data storage path
Go to C:\Program Files\MongoDB\Server\3.4\bin using cmd and
write mongod.
Open another cmd by right click and run as admin point to your
monogodb installed directory as mentioned above and then just like
write this mongo.exe
After that, write db.test.save({Field:'Hello mongodb'}) this command
will insert a field having name Field and value is Hello
mongodb.
After, check the record db.test.find() and press enter you will find
the record that you have recently entered.
Steps to start a certain local MongoDB instance and to connect to in from NodeJS app:
Create mongod.cfg for a new database using the path C:\Program Files\MongoDB\Server\4.0\mongod.cfg with the content
systemLog:
destination: file
path: C:\Program Files\MongoDB\Server\4.0\log\mongod.log
storage:
dbPath: C:\Program Files\MongoDB\Server\4.0\data\db
Install mongoDB database by running
mongod.exe --config "C:\Program Files\MongoDB\Server\4.0\mongod.cfg" --install
Run a particular mongoDB database
mongod.exe --config "C:\Program Files\MongoDB\Server\4.0\mongod.cfg"
Run mongoDB service
mongo 127.0.0.1:27017/db
and !see mongoDB actual connection string to coonect to the service from NodeJS app
MongoDB shell version v4.0.9
connecting to: mongodb://127.0.0.1:27017/db?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("c7ed5ab4-c64e-4bb8-aad0-ab4736406c03") }
MongoDB server version: 4.0.9
Server has startup warnings:
...
For this error, if you are using windows 7 or windows server 2008 R2, the problem could be that you have to install a microsoft hotfix.
Refer to this link: https://support.microsoft.com/en-us/kb/2731284

Mongo DB Make directory for the first time [duplicate]

If someone can provide some insights here I would GREATLY appreciate it.
I had a express/node.js app running on MongoDB locally successfully, but upon restarting my computer, I attempted to restart the Mongo server and it began giving errors and wouldn't start. Since then, I have re-installed Mongo several times only to find the same error occurring. this is what I am receiving:
privee:mongodb-osx-x86_64-2.4.6 jonlinton$ ./bin/mongo
MongoDB shell version: 2.4.6
connecting to: test
Mon Aug 26 14:48:47.168 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
Am I missing a step? Should I be creating a config file?
If you have installed mongodb through homebrew then you can simply start mongodb through (mongodb-community if installted mongodb-community
brew services start mongodb
OR
brew services start mongodb-community
Then access the shell by
mongo
You can shut down your db by
brew services stop mongodb
You can restart your db by
brew services restart mongodb
For more options
brew info mongodb
Updated answer (9/2/2019):
Homebrew has removed mongodb formula from its core repository, see this pull request.
The new way to install mongodb using Homebrew is as follows:
~> brew tap mongodb/brew
~> brew install mongodb-community
After installation you can start the mongodb service by following the caveats:
~> brew info mongodb-community
mongodb/brew/mongodb-community: stable 4.2.0
High-performance, schema-free, document-oriented database
https://www.mongodb.com/
Not installed
From: https://github.com/mongodb/homebrew-brew/blob/master/Formula/mongodb-community.rb
==> Caveats
To have launchd start mongodb/brew/mongodb-community now and restart at login:
brew services start mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
Deprecated answer (8/27/2019):
I assume you are using Homebrew. You can see the additional information that you need using brew info $FORMULA
~> brew info mongo 255
mongodb: stable 2.4.6, devel 2.5.1
http://www.mongodb.org/
/usr/local/Cellar/mongodb/2.4.5-x86_64 (20 files, 287M) *
Built from source
From: https://github.com/mxcl/homebrew/commits/master/Library/Formula/mongodb.rb
==> Caveats
To reload mongodb after an upgrade:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Caveats is what you need to follow after installation.
Assuming you have created the data/db directory under bin after install.
Start a terminal for your mongo server
Go to <mongodb-install-directory>/bin directory
Run the command
./mongod
Start a terminal for your mongo shell
Go to <mongodb-install-directory>/bin directory
Run the command (make sure you put the name of the database)
./mongo test
Problem here is you are trying to open a mongo shell without starting a mongo db which is listening to port 127.0.0.1:27017(deafault for mongo db) thats what the error is all about:
Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145 exception: connect failed
The easiest solution is to open the terminal and type
$ mongod --dbpath ~/data/db
Note: dbpath here is "Users/user" where data/db directories are created
i.e., you need to create directory data and sub directory db in your user folder.
For e.g say `
/Users/johnny/data
After mongo db is up. Open another terminal in new window and type
$ mongo
it will open mongo shell with your mongo db connection opened in another terminal.
Mac Installation:
Install brew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update and verify you are good with
brew update
brew doctor
Install mongodb with
brew install mongodb
Create folder for mongo data files:
mkdir -p /data/db
Set permissions
sudo chown -R `id -un` /data/db
Open another terminal window & run and keep running a mongo server/daemon
mongod
Return to previous terminal and run a mongodb shell to access data
mongo
To quit each of these later:
The Shell:
quit()
The Server
ctrl-c
For those that could be facing the same problem and the solutions suggested above aren't working, for example in my case, I had installed mongodb-community, so you might wanna run the command below to restart your mongo server.
For those that installed mongodb-community using brew
brew services start mongodb-community
additionally you may want mongo to run on another port, then paste this command on terminal,
mongod --dbpath /data/db/ --port 27018
where 27018 is the port we want mongo to run on
assumptions
mongod exists in your bin i.e /usr/local/bin/ for mac ( which would be if you installed with brew), otherwise you'd need to navigate to the path where mongo is installed
the folder /data/db/ exists
mongo => mongo-db console
mongodb => mongo-db server
If you're on Mac and looking for a easier way to start/stop your mongo-db server, then MongoDB Preference Pane is something that you should look into. With it, you start/stop your mongo-db instance via UI. Hope it helps!
Make sure you are logged in as root user in your terminal.
Steps to start mongodb server in your mac
Open Terminal
Run the command sudo su
Enter your administrator password
run the command mongod
MongoDb Server starts
Hope it helps you.
Thanks
Nothing less likely to be outdated that the official docs: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/
What worked for me on MacOS 12.6.1:
Go to Homebrew copy the "Install Brew " link from there , paste and run .run
To check the version of brew
brew
or
brew -v
then
brew tap mongodb/brew
brew install mongodb-community
sudo mkdir -p /System/Volumes/Data/data/db
sudo chown -R `id -un` /System/Volumes/Data/data/db
sudo mongod --dbpath /System/Volumes/Data/data/db
this would run your MongoDB .
Download MongoDB and install it on your local machine.
Link https://www.mongodb.com/try/download/enterprise
Extract the file and put it on the desktop.
Create another folder where you want to store the data. I have created mongodb-data folder.
Then run the below command.
Desktop/mongodb/bin/mongod --dbpath=/Users/yourname/Desktop/mongodb-data/
Before the hyphen is the executable path of your mongoDB and after hyphen is your data store.

MongoDB : A Service Specific error occurred :100

I have just installed "mongodb" on Windows, while starting it, the following error appears
A Service Specific error occurred :100
Any Suggestions?
The reason for this error message is that you have another process already established.
In my case it was the mongod.exe file I had opened in CMD, when I closed it and restarted the net start MongoDB command, it connected successfully.
BTW i am using Windows 10 current build as of July 2017 with MongoDB 3.4
Please try running the below commands as Administrator in the comment prompt.
mongod --repair
mongod --remove
then like #Yahya did, specify the log path,
mongod --install --logpath C:\data\db\log\mongo.log
net start mongodb
Hope it helps.
For me, somehow directories I have specified for db and log config file were not auto created.
dbpath=\data\db
logpath=\data\log\mongo.log
so I created them manually then ran the command again and service started.
I am using v3.4.9 om Windows 10
Check your Mongo log in your /data/log folder (which you should have created during install), there might be a solution in there.
I had this issue, I checked the System Event Log which gave me the following:
The MongoDB service terminated with the following service-specific error: Cannot create another system semaphore.
When I checked the log I found this:
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?
Turns out I'd started the process manually in another command window so it couldn't start it again. You may have a different issue but the log should tell you what is going on!
execute the command
"C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe"
and check which error is displayed
Running mongod.exe through a service does not display the error messages. In my case, i didnt created the directory /data/db, which i specified in my configuration file. My Configuration file is based on the docs create-a-configuration-file
The error was only displayed after executing the command directly
For example mongoDB version 3.6 is installed, and the installing path of MongoDB is "D:\Program Files\MongoDB".
Create folder D:\mongodb\logs, then create file mongodb.log inside this folder.
Run cmd.exe as administrator,
D:\Program Files\MongoDB\Server\3.6\bin>taskkill /F /IM mongod.exe
D:\Program Files\MongoDB\Server\3.6\bin>mongod.exe --logpath D:\mongodb\logs\mongodb.log --logappend --dbpath D:\mongodb\data --directoryperdb --serviceName MongoDB --remove
D:\Program Files\MongoDB\Server\3.6\bin>mongod --logpath "D:\mongodb\logs\mongodb.log" --logappend --dbpath "D:\mongodb\data" --directoryperdb --serviceName "MongoDB" --serviceDisplayName "MongoDB" --install
Remove these two files mongod.lock and storage.bson under the folder "D:\mongodb\data".
Then type net start MongoDB in the cmd using administrator, the issue will be gone.
This error occurs due to that service is already started. If you are not done it, then please check your database path and log path in the mongodb.cfg (The file which stores mongodb configuration) file.
Eg:
systemLog:
destination: file
path: H:\data\log\mongod.log
storage:
dbPath: H:\data\db
processManagement:
windowsService:
serviceName: "MongoDB"
displayName: "Mongo DB"
description: "mongod service"
If you doesn't have it then please create one.
Also you can use the following step to fix this issue,
please run the follow as administrator.
sc.exe qc MongoDB
If there are no logs, then MongoDB likely cannot open the log file due to a permission issue.
Also, try installing the service as
D:\servers\db\mongodb\bin\mongod.exe --dbpath=D:\servers\db\mongodb\data --logpath=D:\servers\db\mongodb\log\mongo.log --logappend --install
I fixed my issue
In the config one of the path was
C:\MongoDB\data\db
But nor the data or db folder existed
I expected them to be generated automatically.

MongoDB 3.0 Windows Service Start : System Error 2 has occured

I have downloaded the MongoDB Windows msi install and run this successfully.
The mongod.exe and mongo.exe command file executions work properly.
The installation manual shows how to create the configuration file, and then to create the Windows Server using the command
sc.exe create MongoDB binPath= "\"C:\mongodb\mongod.exe\" --service --config=\"C:\mongodb\mongod.cfg\""
This creates a SUCCESS response.
The service is then started
net start MongoDB
but this produces the response
System Error 2 has occurred.
The system cannot find the file specified.
The resolution, for those who need this, is that the manual indicates the incorrect default path for mongod.exe, which should be in the bin directory
C:\mongodb\bin\mongod.exe
Thus, whereas this is a question, I have also solved this for the benefit of others who may have this problem.
Also, by default, MongoDB will install in C:\Program Files in Windows, and you should use the custom install to put it into C:\mongodb.
It can be possible that you already have a service named "MongoDB" before your installation and thus it is not successfully installed.
try to remove the previous one using this:
"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --remove
and then you can try install the service again and fire the net start MongoDB command. It should work now.
I have faced this problem.And I solved as below.
1) Create this folders
C:\data\db
C:\data\log
2)Run CMD as administrator
C:\Windows\System32\cmd.exe
3)If you've installed service , write below to cmd to remove
C:\Program Files\MongoDB\Server\3.6\bin> mongod.exe --remove
4) This is important , I don't use sc.exe Determine the log and db directory ,and instal service
C:\Program Files\MongoDB\Server\3.6\bin> mongod.exe --logpath c:\data\log\mongod.log --dbpath c:\data\db --directoryperdb --install
5)If success
net start MongoDB
After having installed mongodb in C:\mongodb you just do:
mongod --install --logpath C:\mongodb\logs\mongo.log
The path to the logfile must exist and it must be an absolute Windows path. Then you start the MongoDB service by typing:
net start MongoDB

getting an error when firing up mongodb in terminal [duplicate]

I'm getting the following error when I try to run "mongod" in the terminal. I've tried uninstalling, reinstalling, and restarting the machine. Any suggestions on how to get it working would be amazing.
ERROR:
dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
Side note:
Node also stopped working on my machine around the same time that I got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
Any help would be much appreciated!
This should work to ensure that the directory is set up in the right place so that Mongo can find it:
sudo mkdir -p /data/db/
sudo chown `id -u` /data/db
You need to create the directory on root /data/db or set any other path with the following command :
mongod --dbpath /srv/mongodb/
See the example link
I solved the problem with :
sudo mongod --dbpath=/var/lib/mongodb and then mongo to access the mongodb Shell.
Change the user of the new data directory:
chown mongodb [rute_directory]
And try another time to start the mongo service
service mongod start
I solve the same problem with this.
Daemons (usually ending with d) are normally started as services. Starting the service (daemon) will allow mongodb to work as designed (without permission changes if integrates well with your distro). I start it using the service named mongodb instead of starting mongod directly--on distro with systemd enable on startup then run like:
sudo systemctl enable mongodb
sudo systemctl start mongodb
or, on distro with upstart (if you have /etc/init) or init (if you have /etc/init.d) ( https://www.tecmint.com/systemd-replaces-init-in-linux/ ) instead run:
sudo service mongodb enable
sudo service mongodb start
If you have a distro with rc ("run commands") such as Gentoo (settings in /etc/init.d) (https://forums.gentoo.org/viewtopic-t-854138-start-0.html) run:
rc-update add mongodb default
/etc/init.d/mongodb start
In a distro/version of FreeBSD which still has rc (check whether your version switched to systemd, otherwise see below):
add the following line to /etc/rc.conf:
mongod_enable="YES"
then:
sudo service mongod start
After starting the service, an unpriveleged user can use mongo, and each user will have separate data.
I also got the error that "The file /data/db doesn't exist" when I tried to save my file using the "mkdir -p /data/db" command(using both with and without sudo command). But later on one site, a person named Emil answered that the path "/data/db" no longer works on Mac, so use "~/data/db" instead
i.e., use the command
mkdir -p ~/data/db
instead of previous command.
Moreover, use
mongod --dbpath ~/data/db
to run mongod
It worked for me, hope it work for others too facing the same problem