could not connect to MongoDB - javascript

I have an issue using the mean.io tutorial to create the default mean app. i have mongodb install what could be ths issue this is the error.That is the error below. Thanks.
PS C:\Users\Truparse Creative\Documents\myMeanProject\lisavogue> npm test
> mean#0.5.5 test C:\Users\Truparse Creative\Documents\myMeanProject\lisavogue
> gulp test
Invoking gulp - development
[08:40:17] Using gulpfile ~\Documents\myMeanProject\lisavogue\gulpfile.js
[08:40:17] Starting 'startServer'...
Error: connect ECONNREFUSED 127.0.0.1:27017
**Could not connect to MongoDB. Please ensure mongod is running and restart MEAN app.**

in your terminal, type mongod to start mongodb and leave it running. Then, open a new terminal tab(or window) and try running your application again.
You need the mongodb server to be running to be able to use it. It looks like you're not running it.
You can also access the mongo shell by running mongo in your terminal to look at the server, collections, perform queries, etc.

Related

MongoDB no longer starts after updating

I recently updated my MongoDB server from 3.2 to 3.6 to fix some errors with naming. When I had my Mongo server as 3.2 it did work fine.
I downloaded the MongoDB 3.6 from https://www.mongodb.com/download-center/community and installed it with the package manager (sudo dpkg -i mongodb-org-server_3.6.12_amd64.deb) and I have verified that the server did update with mongod --version.
As far as I know, starting the system works, but when I run mongo, or sudo mongo, it gives me the following output
MongoDB shell version: 3.2.22
connecting to: test
2019-05-14T13:28:09.049-0400 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: errno:111 Connection refused
2019-05-14T13:28:09.049-0400 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
I'm not sure how I could fix the problem either, I have tried to restart the service and restarting the server it's running on (Ubuntu 16.04) and neither worked. Nothing I found online could help either so if you know a possible solution, please let me know, thanks!
Before that, try with
sudo service mongod stop
sudo rm /var/lib/mongodb/mongod.lock
mongod –repair
sudo service mongod start

mongod command not found (OS X) [duplicate]

I've installed mongodb and have been able to run it, work with it, do simple DB read / write type stuff. Now I'm trying to set up my Mac to run mongod as a service.
I get "Command not found" in response to:
init mongod start
In response to:
~: service mongod start
service: This command still works, but it is deprecated. Please use launchctl(8) instead.
service: failed to start the 'mongod' service
And if I try:
~: launchctl start mongod
launchctl start error: No such process
So obviously I'm blundering around a bit. Next step seems to be typing in random characters until something works. The command which does work is: mongod --quiet & I'm not sure, maybe that is the way you're supposed to do it? Maybe I should just take off 'quiet mode' and add > /logs/mongo.log to the end of the command line?
I'm building a development environment on a Mac with the intention of doing the same thing on a linux server. I'm just not sure of the Bash commands. All the other searches I do with trying to pull up the answer give me advice for windows machines.
Perhaps someone knows the linux version of the commands?
Thanks very much
Edit: you should now use brew services start mongodb, as in Gergo's answer...
When you install/upgrade mongodb, brew will tell you what to do:
To have launchd start mongodb at login:
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
mongod
It works perfectly.
With recent builds of mongodb community edition, this is straightforward.
When you install via brew, it tells you what exactly to do. There is no need to create a new launch control file.
$ brew install mongodb
==> Downloading https://homebrew.bintray.com/bottles/mongodb-3.0.6.yosemite.bottle.tar.gz ### 100.0%
==> Pouring mongodb-3.0.6.yosemite.bottle.tar.gz
==> Caveats
To have launchd start mongodb at login:
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
🍺 /usr/local/Cellar/mongodb/3.0.6: 17 files, 159M
Homebrew's services tap integrates formulas with the launchctl manager. Adding it is easy:
brew tap homebrew/services
You can then launch MongoDB with this command (this will also start mongodb on boot):
brew services start mongodb
You can also use stop or restart:
brew services stop mongodb
brew services restart mongodb
If you feel like having a simple gui to fix this (as I do), then I can recommend the mongodb pref-pane. Description: https://www.mongodb.com/blog/post/macosx-preferences-pane-for-mongodb
On github: https://github.com/remysaissy/mongodb-macosx-prefspane
Just installed MongoDB via Homebrew. At the end of the installation console, you can see an output as follows:
To start mongodb:
brew services start mongodb
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
So, brew services start mongodb, managed to run MongoDB as a service for me.
I did a bit of looking around on the Mac side. You may want to use the installer here as it looks like it does all the setup for you to automatically launch on Mac OS. The only downside is it looks like it's using a pretty old mongo version.
This link here also explains the setup to get mongo automatically launching as a background service on the Mac.
First Step
install mongodb in your linux machine with
apt install mongodb-client && apt install mongodb-server
second step is
change the database path instead of your system default path if you want.
so do the following steps and change it for yourself.
mongod --directoryperdb --dbpath /var/lib/mongodb/data/db --logpath /var/lib/mongodb/log/mongodb.log --logappend --rest
and in your windows machine do it just like that just put an --install flag.
you have to get a successful message.
Best Regards...
On macOS 10.13.6 with MongoDB 4.0
I was unable to connect to localhost from the mongo shell
I started MongoDB with:
mongod --config /usr/local/etc/mongod.conf
I found that the 'mongod.conf' had:
bindIp: 127.0.0.1
Change my JavaScript connection from localhost to 127.0.0.1 and it worked fine.
The same was occurring with MongoDB Compass too.
mongod wasn't working to start the daemon for me but after I ran the following, it started working:
'mongod --fork --logpath /var/log/mongodb.log'
(from here: https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/)
After installing mongodb through brew, run this to get it up and running:
mongod --dbpath /usr/local/var/mongodb
mongod --dbpath [path_to_data_directory]

Node.JS: Why is my connection to localhost:3000 refused?

I'm a student going into back-end development for the first time and are trying to learn Node.JS. I downloaded a pdf book about Node.JS from sitepoint called: "Jumpstart Node.JS". In following the instructions to set up the server on the command line, install the dependencies, and navigate to localhost:3000, i got nothing except the following message: "Connection refused: localhost:3000", Can somebody please tell me what might have went wrong and how to fix it?
Edit1:
The instructions i followed is about setting up a node.js server using the Node command line, thus no code, simply cmd commands, however, here is a quick summary of the process i followed:
Created an account on MongoLabs and then a database using the free pricing plan.
Installed express using the command: npm install -g express#.2.5.8.
Created an applications with default options using this command: express authentication.
modified the package.json file in system32
installed the dependencies by typing cd authentication, hitting enter, and then typing the command: npm install
Typed node app and hit enter.
According to the instructions i should have seen a message: "Welcome to express" but instead got the error message.
In following the instructions to set up the server on the command line, install the dependencies, and navigate to localhost:3000
It seems that you didn't start the server.
Somewhere between installing the dependencies and navigating to the URL you need to actually start the server if you want it to serve the request.
Check that there is no copy of the server running in the background, or that another app is using the port currently.
(Your firewall show allow you to see which app has been allocated to that port)
Because nodejs requires it to be the only app on that port running on your computer.
Also try a different port maybe?

Problems with MongoDB trying to deploy a Meteor App

I have been setting up a server on a Digital Ocean droplet in order to host a couple of Meteor apps. I'm doing everything from scratch so I can learn as much as possible. I am trying to use "Meteor-Up" (mup) to deploy an app, but it is having problem communicating with MongoDB. When I run "mup setup" I get the following error:
Started TaskList: Setup (linux)
[Gibson] - Installing Docker
[Gibson] - Installing Docker: SUCCESS
[Gibson] - Setting up Environment
[Gibson] - Setting up Environment: SUCCESS
[Gibson] - Copying MongoDB configuration
[Gibson] - Copying MongoDB configuration: SUCCESS
[Gibson] - Installing MongoDB
[Gibson] x Installing MongoDB: FAILED
-----------------------------------STDERR-----------------------------------
docker: Error response from daemon: driver failed programming external connectivity on endpoint mongodb (1e188b51b171446cd22d96f40ceab1e696019e5ac33ca713d78827246ae37ec8): Error starting userland proxy: listen tcp 127.0.0.1:27017: bind: address already in use.
-----------------------------------STDOUT-----------------------------------
latest: Pulling from library/mongo
Digest: sha256:beff97308c36f7af664a1d04eb6ed09be1d14c17427065b2ec4b0de90967bb3f
Status: Image is up to date for mongo:latest
mongodb
c17e5ac9e9369b779da4aff639c16578dedbc7c357985f67d6e7b005d9cf3939
----------------------------------------------------------------------------
But I can't get from this any indication of what's going wrong. Is the problem with Mongo, Meteor, mup, or docker?
EDIT:
So far I understand from the message that "mup" is trying to connect to Mongo on port 27017 and is failing, I just don't understand why or how to fix it. I have a database that I want the app to connect to, which I moved onto the server from my local machine using mongodump and mongorestore. The thing I can't solve is how to connect my meteor app to that mongo DB.
It does not just try to connect to mongod, but it installs mongod in a container and tries to bind port 27017 to local interface.
If you already have mongodb installed and prefer to use it instead, you need to disable installation of mongodb in mup.js, mup.json, or whatever configuration file is being used in your version of mup.

Mongodb Not connecting in Node js

In Node js using mongodb for saving user chat and users. All the work is done on local. Mongodb work properly but today not connected and return following error.
{ [MongoError: connect ECONNREFUSED] name: 'MongoError', message: 'connect ECONNREFUSED'
and my code is
Sounds like mongod server isn't running. The mongod command won't work if your MongoDB installation doesn't have rights outside the core mongo directory. This is common on Windows installations, especially.
Try changing your working directory in your terminal to your Mongo installation directory. On a Windows machine, e.g. cd C:\Program Files\Mongo then run mongod --dbpath (yourAppDBdirectory).

Categories

Resources