How to start mongodb with new dbPath in a mongo session? - mongodb

I have installed mongo on my server with sudo yum install mongo, i am using mongo to connect to my remote servers that actually have MongoDB installed on them (amazon servers).
At some point (during the backup restore) i need to issue a command like mongod --dbpath /$dbPath --replSet $replicaSetName on my MongoDb server, how can i do this from a mongo session? or if it is not possible, then how can i get the installation path to mongod?
Another thing is, i also have an mms account, is it possible to use their installed agent (on mongodb server) todo that?
thank you

Related

Can I restart mongodb server through mongo shell?

Can I restart a MongoDB server through the mongo CLI client?
You can't stop and start (restart) it from the client. As i.kimiko already mentioned, you can shut it down on your client with db.shutdownServer() through a mongo shell database methods documentation 3.6.0
But then you'd still have to connect to the server and restart it from there with sudo service mongodb start for example.
You can shutdown server via client.
mongo --host "hostname where server or IP" --port "port of mondodb server" --username "username" --password "password"
use admin
db.shutdownServer()
link to documentation about db.shutdownServer() mongodb 3.6.0
After that you may up that server via other service\tool (from a host machine when a mongodb server installed), like cron for example or using systemd unit.

Connect mongo with meteor in production

I have deployed my meteor application on localhost for demo purpose by following what was mentioned here.
$export MONGO_URL='mongodb://localhost'
$ export PORT=3000
$ export ROOT_URL='http://example.com'
$ node main.js
I have had a bunch of collections in my meteor's mongo instance while development and need to move it to the new db that the deployed version connects to. I've taken a mongo dump of that and I know how to restore it. My question is, how exactly do I connect to the mongo db in order to do this?
I've tried:
mongo localhost
mongo localhost:3000
mongo -U localhost
They don't seem to work.
NOTE -
I do not want to run the mongo in development environment using meteor mongo. I have to deploy this in the client machine.
You can use the Meteor command line tools to attach to your local meteor instance.
meteor mongo
Taken from https://docs.meteor.com/commandline.html#meteormongo
Also, I think your commands didn't work 'cause the meteor mongo instance is hosted on port 3001 instead of 3000. Port 3000 hosts the actual meteor app, 3001 is the mongo instance.
As k.chao.0424 says you can use meteor mongo to connect to the mongo db via terminal or command line if you are using windows. But as i see you used the port 3000 for mongodb. I suggest you a simple way you just run the follwing command to run meteor and mongo db just write on your terminal:-
meteor
or if you are using ubuntu and any permission issues than write:-
sudo meteor
It will automatically run your project on 3000 port and your mongdb in 3001 port as by default after running app you can connect with mongodb via following command:-
meteor mongo
Hope this will help!

Cannot access to my datsbase when running the server as a service

I have recently installed Mongodb on my ubuntu machine according to the linux manual in mongodb website. everything looks ok when i run the command "mongod" to start a mongodb server.when I try to run
sudo service mongod start
it says that mongod start/running, proccess 3369
but when I try to access the database from the Mongodb GUI it cannot acces it. nor from the chrome itself using the port 27017.
how can i fix this?

Cannot connect to mongod running in Ubuntu machine

I would like to connect with mongo from a cmd shell in windows to a mongod database running in a Ubuntu virtual machine.
mongo is running fine in the Ubuntu terminal and from a putty shell
When I use mongo from a windows cmd shell, I got this error:
mongo.exe --host 192.168.1.6 --port 27017
MongoDB shell version: 2.4.6
connecting to: 192.168.1.6:27017/test
Sat Feb 01 14:45:32.181 Error: couldn't connect to server 192.168.1.6:27017 at src/mongo/shell/mongo.js:147
exception: connect failed
What should I do to be able to connect?
My goal is to use MongoVue to connect to the mongod database in the Ubuntu machine (by the way, MongoVue is not connecting even using its SSH options).
I am trying to connect to the mongod instance of a meteorjs application.
The meteor application is up and running and I can connect to the mongod instance running on the Ubuntu machine at port 3002, both in the Ubuntu terminal and with a putty shell.
stefano#MeteorDeploy:~$ mongo --port 3002
MongoDB shell version: 2.0.4
connecting to: 127.0.0.1:3002/test
PRIMARY> show dbs
local 0.0625GB
meteor 0.0625GB
I would like to connect to the mongod instance using MongoVue as alternative of the putty shell.
I did as in the docs.mongodb.org/manual/tutorial/configure-linux-iptables-firewall/ but without success.
Meteor runs it's own instance of mongo per app. As you note since your edit, when you ssh into your VM you use --port 3002 to connect.
Now you could add that port to your mongo shell launch except for one problem
ps -ef | grep mongo
on your VM will show you the running instance of mongo along with it's startup options. By default this will be bound to 127.0.0.1 which is the loopback adaptor and not accessible outside of the VM.
So what you need to do is either change the startup options in your project, or use another instance on mongo installed on the local machine.
export MONGO_URL=mongodb://localhost:27017/your_db
By default mongod insllation on Ubuntu only listen to localhost, so you can't connect from Windows.
Edit /etc/mongodb.conf and change the bind_ip line (add your windows IP adress on the local network) so it will accept connection.
Be aware that by default mongod does not require authentification so you would maybe want to settup one.
Doc is here :
http://docs.mongodb.org/manual/reference/configuration-options/#bind_ip
For quick and dirty solution (not for Production):
Edit /etc/mongodb.conf and change the bind_ip to 0.0.0.0

How to identify the port of minimongo running inside meteor?

I am novice in meteor. I was developing an application which leverages the mongo db which comes with the meteor package. The meteor is running under the port 3000, but i want to know under what port the mini mongo runs. I am using a tool MongoVUE to view all the collections that is under mongo running in a port. I was able to view the mongo collections when i run the standalone mongo since i know the port for that but for this mini mongo running under meteor i am not able to know the port. Any help is appreciated.
Mingomongo runs in the browser, it's a client-side Javascript library.. it runs in memory, it doesn't have a port.. it enables you to query data published by the server in your client application, using MongoAPI style syntax..
to get the connection string of the Mongo instance running on the server (say, if you want to connect from a different client, or just see the port number) run
meteor mongo -U
Using ps auxww|grep mongo|grep meteor on my Fedora system I get:
jwulf 20635 0.3 2.6 150800 41336 pts/1 Sl+ 17:07 0:01 /usr/lib/meteor/mongodb/bin/mongod --bind_ip 127.0.0.1 --smallfiles --port 3002 --dbpath /home/jwulf/tools/leaderboard/.meteor/local/db
So it is running on port 3002 on my system. Starting mongo with --port 3002 allows me to connect to the Meteor mongo server and copy data into the database.
You can also connect to the local instance by running meteor mongo in your Meteor app directory.
The database itself is at <app-name>/.meteor/local/db on my Fedora system.
In meteor 0.8.3 it's using port 3001
so I run:
mongo localhost:3001
use use meteor
and I'm good to go...thanks to Sitapati Das for the command above...