Reputation: 10992
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
Upvotes: 43
Views: 131636
Reputation: 21765
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:
...
Upvotes: 1
Reputation: 1092
If you are getting these type of errors when running mongod from command line or running mongodb server,
then follow these steps,
Upvotes: 4
Reputation: 11
mongo.exe
db.test.save({Field:'Hello mongodb'})
this command
will insert a field having name Field and value is Hello
mongodb.db.test.find()
and press enter you will find
the record that you have recently entered.Upvotes: 1
Reputation: 61
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
Upvotes: 2
Reputation: 11
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
Upvotes: 0
Reputation: 269
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
Upvotes: 26
Reputation: 1028
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
Upvotes: 32
Reputation: 225
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.
Upvotes: 9
Reputation: 51
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
Upvotes: 5
Reputation: 571
you can use below command,
mongod --dbpath=D:\home\mongodata
where D:\home\mongodata is the data storage path
Upvotes: 1
Reputation: 621
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.
Upvotes: 57