How to start mongo v4.2.0 [duplicate] - mongodb

This question already has an answer here:
Installing MongoDB on Ubuntu 16.04 [closed]
(1 answer)
Closed 3 years ago.
I have successfully installed Mongo v4.2.0.
mongo --version
MongoDB shell version v4.2.0
git version: a4b751dcf51dd249c5865812b390cfd1c0129c30
OpenSSL version: OpenSSL 1.1.1c 28 May 2019
allocator: tcmalloc
modules: none
build environment:
distmod: ubuntu1804
distarch: x86_64
target_arch: x86_64
But when i start mongo, it is showing error. Kindly help me out. I am using ubuntu 18.04.
mongo
MongoDB shell version v4.2.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2019-10-07T11:35:13.915+0530 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:341:17
#(connect):2:6
2019-10-07T11:35:13.916+0530 F - [main] exception: connect failed
2019-10-07T11:35:13.916+0530 E - [main] exiting with code 1

First start your mongodb instance
mongod --port <your-choice-of-port> --dbpath=/path-of-your-db
and then connect to it.

Related

Can't connect with DNS Seedlist Connection Format but works fine with standard connection string

I am trying to connect to my atlas cluster but it gives me time out error. I tried connecting to local mongodb, it works and using standard connection string for the same cluster:
(mongo "mongodb://cluster0-shard-00-00-n1kmr.mongodb.net:27017,cluster0-shard-00-01-n1kmr.mongodb.net:27017,cluster0-shard-00-02-n1kmr.mongodb.net:27017/test?replicaSet=Cluster0-shard-0" --ssl --authenticationDatabase admin --username <username> --password <password>)
works too!
However, when I try to connect with DNS Seedlist Connection Format, it gives me a timeout error when I run
mongo "mongodb+srv://cluster0-n1kmr.mongodb.net/test" --username <username>
Error message:
DNSHostNotFound: Failed to look up service "":This operation returned because the timeout period expired.
cmd line image with error message
My mongo shell version is v4.2.6
>>mongo --version
MongoDB shell version v4.2.6
git version: 20364840b8f1af16917e4c23c1b5f5efd8b352f8
allocator: tcmalloc
modules: none
build environment:
distmod: 2012plus
distarch: x86_64
target_arch: x86_64
and db version v4.2.6
>> mongod --version
db version v4.2.6
git version: 20364840b8f1af16917e4c23c1b5f5efd8b352f8
allocator: tcmalloc
modules: none
build environment:
distmod: 2012plus
distarch: x86_64
target_arch: x86_64

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed mongodb [duplicate]

This question already has answers here:
Mongo is unable to start
(8 answers)
mongo - couldn't connect to server 127.0.0.1:27017
(46 answers)
Mongod complains that there is no /data/db folder
(28 answers)
Closed 3 years ago.
MongoDB is not connecting to my nodejs app earlier it was working fine but I don't know why this is not working when tried to run using shell I get this error
C:\Users\adity>mongo
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017
2019-04-20T09:25:45.799+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017 after 5000ms milliseconds, giving up.
2019-04-20T09:25:45.802+0530 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
I followed this answer to which I found in StackOverflow this is the link but it still gives the same error.
Anyone please help me to fix this.
while trying to start mongod i get this
C:\Users\adity>mongod
2019-04-19T21:12:16.552-0700 I CONTROL [initandlisten] MongoDB starting : pid=8888 port=27017 dbpath=C:\data\db\ 64-bit host=DESKTOP-H4VG30N
2019-04-19T21:12:16.552-0700 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2019-04-19T21:12:16.555-0700 I CONTROL [initandlisten] db version v3.6.5
2019-04-19T21:12:16.558-0700 I CONTROL [initandlisten] git version: a20ecd3e3a174162052ff99913bc2ca9a839d618
2019-04-19T21:12:16.558-0700 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2o-fips 27 Mar 2018
2019-04-19T21:12:16.559-0700 I CONTROL [initandlisten] allocator: tcmalloc
2019-04-19T21:12:16.559-0700 I CONTROL [initandlisten] modules: none
2019-04-19T21:12:16.560-0700 I CONTROL [initandlisten] build environment:
2019-04-19T21:12:16.560-0700 I CONTROL [initandlisten] distmod: 2008plus-ssl
2019-04-19T21:12:16.561-0700 I CONTROL [initandlisten] distarch: x86_64
2019-04-19T21:12:16.562-0700 I CONTROL [initandlisten] target_arch: x86_64
2019-04-19T21:12:16.562-0700 I CONTROL [initandlisten] options: {}
2019-04-19T21:12:16.566-0700 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory C:\data\db\ not found., terminating
2019-04-19T21:12:16.569-0700 I CONTROL [initandlisten] now exiting
2019-04-19T21:12:16.569-0700 I CONTROL [initandlisten] shutting down with code:100

mongo local server uninstallition

I'm try to uninstall mongod but it's give
message of file / package missing
during installation it's show message
of no newly file install ...............
dz-gg-04#dz-gg-04:~$ sudo apt-get install -y mongodb
Reading package lists... Done
Building dependency tree
Reading state information... Done
mongodb is already the newest version (1:3.6.3-0ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 26 not upgraded.
dz-gg-04#dz-gg-04:~$ mongod
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] MongoDB starting : pid=4627 port=27017 dbpath=/data/db 64-bit host=dz-gg-04
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] db version v3.6.3
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0g 2 Nov 2017
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] allocator: tcmalloc
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] modules: none
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] build environment:
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] distarch: x86_64
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] target_arch: x86_64
2018-10-19T15:25:00.599+0530 I CONTROL [initandlisten] options: {}
2018-10-19T15:25:00.600+0530 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2018-10-19T15:25:00.600+0530 I CONTROL [initandlisten] now exiting
2018-10-19T15:25:00.600+0530 I CONTROL [initandlisten] shutting down with code:100
dz-gg-04#dz-gg-04:~$ mongo
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
2018-10-19T15:26:04.016+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2018-10-19T15:26:04.016+0530 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
dz-gg-04#dz-gg-04:~$ sudo service mongod start
Failed to start mongod.service: Unit mongod.service not found.
dz-gg-04#dz-gg-04:~$ ^C
dz-gg-04#dz-gg-04:~$ ^C
dz-gg-04#dz-gg-04:~$ ^C
dz-gg-04#dz-gg-04:~$ ^C
dz-gg-04#dz-gg-04:~$ ^C
dz-gg-04#dz-gg-04:~$ sudo service mongod start
exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
Create the directory /data/db

MongoError: failed to connect to server [localhost:27017] on first connect

I have paid a membership and downloaded this project. After npm install and node app.js, it returns the following error:
Does anyone know what's wrong?
/Users/Thomas/Desktop/mean-stack-tutorial-01$ node app.js
/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb/lib/server.js:265
process.nextTick(function() { throw err; })
^
MongoError: failed to connect to server [localhost:27017] on first connect
at Pool.<anonymous> (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/topologies/server.js:325:35)
at emitOne (events.js:96:13)
at Pool.emit (events.js:188:7)
at Connection.<anonymous> (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/connection/pool.js:270:12)
at Connection.g (events.js:292:16)
at emitTwo (events.js:106:13)
at Connection.emit (events.js:191:7)
at Socket.<anonymous> (/Users/Thomas/Desktop/mean-stack-tutorial-01/node_modules/mongodb-core/lib/connection/connection.js:173:49)
at Socket.g (events.js:292:16)
at emitOne (events.js:96:13)
at Socket.emit (events.js:188:7)
at emitErrorNT (net.js:1281:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
Edit 1: Following the comments, I just installed mongo via brew, and did brew services start mongodb and then mongo:
/Users/Thomas$ mongo
MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.1
Server has startup warnings:
2017-01-12T19:53:01.868+0800 I CONTROL [initandlisten]
2017-01-12T19:53:01.869+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-01-12T19:53:01.869+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-01-12T19:53:01.869+0800 I CONTROL [initandlisten]
Then I did
/Users/Thomas$ mongod -httpinterface --dbpath /Users/Thomas/Desktop/MongoDB/db
2017-01-12T20:14:05.620+0800 I CONTROL [initandlisten] MongoDB starting : pid=47356 port=27017 dbpath=/Users/Thomas/Desktop/MongoDB/db 64-bit host=Pro.local
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] db version v3.4.1
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] git version: 5e103c4f5583e2566a45d740225dc250baacfbd7
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2j 26 Sep 2016
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] allocator: system
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] modules: none
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] build environment:
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] distarch: x86_64
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] target_arch: x86_64
2017-01-12T20:14:05.621+0800 I CONTROL [initandlisten] options: { storage: { dbPath: "/Users/Thomas/Desktop/MongoDB/db" } }
2017-01-12T20:14:05.657+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=3584M,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten]
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten]
2017-01-12T20:14:14.108+0800 I CONTROL [initandlisten]
2017-01-12T20:14:14.109+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
2017-01-12T20:14:15.390+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/Users/Thomas/Desktop/MongoDB/db/diagnostic.data'
2017-01-12T20:14:16.303+0800 I INDEX [initandlisten] build index on: admin.system.version properties: { v: 2, key: { version: 1 }, name: "incompatible_with_version_32", ns: "admin.system.version" }
2017-01-12T20:14:16.304+0800 I INDEX [initandlisten] building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2017-01-12T20:14:16.406+0800 I INDEX [initandlisten] build index done. scanned 0 total records. 0 secs
2017-01-12T20:14:16.407+0800 I COMMAND [initandlisten] setting featureCompatibilityVersion to 3.4
2017-01-12T20:14:16.407+0800 I NETWORK [thread1] waiting for connections on port 27017
Then in another terminal, I did node app.js, which hangs (and does not print anything). Then I does http://localhost:28017 in a browser, it seems to work:
However, how could I see the website?
Edit 2:
The normal process is
install mongo
brew services start mongodb in a terminal
mongo & (assume we use the default folder /data/db/)
npm start
see e.g., bin/www for the port number, then use localhost:the_port_number in a browser
Update 2020 Feb 24:
It would be wise to stay tuned with it. Here is the link for latest library instruction:
https://docs.mongodb.com/manual/administration/install-community/
You haven't started your monogo database. first install mongo install mongo as per your OS https://docs.mongodb.com/v3.0/tutorial/
then follow instructions mentioned on this site:
https://docs.mongodb.com/v3.0/tutorial/getting-started-with-the-mongo-shell/
cd .
mongod --dbpath "any directory path to start your database "
and then start your node server. It will work fine.
Hope this helps!!
First open another terminal an run command mongod to start your mongoDB
Then again start you node server npm start or if you have "nodemon" then using nodemon
I think now everything will be fine it will show
Mongoose connected to mongodb://localhost/your_database
I had the same issue but it worked fine after restarting the service
service mongod start

Unable to connect to mongodb in docker container

Getting connection refused when trying to connect to MongoDb in Docker container.
Here's the output of docker ps:
docker ps CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES 21063296d7d8 mongo "/entrypoint.sh mongo"
44 minutes ago Up 29 minutes 0.0.0.0:57017->27017/tcp
mongodb-dev
Here's the snippet of docker logs mongodb-dev:
2015-11-28T05:36:36.363+0000 I CONTROL [initandlisten] db version
v3.0.7 2015-11-28T05:36:36.363+0000 I CONTROL [initandlisten] git
version: 6ce7cbe8c6b899552dadd907604559806aa2e9bd
2015-11-28T05:36:36.363+0000 I CONTROL [initandlisten] build info:
Linux ip-10-183-78-195 3.2.0-4-amd64 #1 SMP Debian 3.2.46-1 x86_64
BOOST_LIB_VERSION=1_49 2015-11-28T05:36:36.363+0000 I CONTROL
[initandlisten] allocator: tcmalloc 2015-11-28T05:36:36.363+0000 I
CONTROL [initandlisten] options: {} 2015-11-28T05:36:36.365+0000 I
NETWORK [initandlisten] waiting for connections on port 27017
Here's the error when connecting to MongoDB in docker using port 57017
mongo localhost:57017
MongoDB shell version: 3.0.7 connecting to: localhost:57017/test
2015-11-27T22:09:22.733-0800 W NETWORK Failed to connect to
127.0.0.1:57017, reason: errno:61 Connection refused 2015-11-27T22:09:22.734-0800 E QUERY Error: couldn't connect to
server localhost:57017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181 exception: connect failed
Please let me know what I'm missing here. Thank you for your help!
It depends if you are using docker directly on a Linux host or on a Mac.
In the latter case, you would need to make sure you have port forwarded 57017 in your VirtualBox connection settings, as I mention in "How to connect mysql workbench to running mysql inside docker?"
VBoxManage controlvm "boot2docker-vm" --natpf1 "tcp-port57017 ,tcp,,57017,,57017"
VBoxManage controlvm "boot2docker-vm" --natpf1 "udp-port57017 ,udp,,57017,,57017"