Can we install 2 versions of mongodb in ubuntu? - mongodb

I am working with 2 projects using 2 different versions of mongodb. One is using 3.2.10 and the other using 2.6. My current system has the latest version, and this is incompatible with the old project.
Is there a way to install & use both version of Mongo?

Yes. You can download two archives and extract them into two different bin directories. You will need to register each instance as a separate service to allow them to be ran in the background. Also configure each one to listen on different port. Obviously each project will need to be configured with correct port.
By default mongod listens on port 27017. You can use any other ports that are not used by other applications. Here is the example of how you can start two mongo services manually. Ports below are chosen arbitrarily.
~/installFolder1/mongod --dbpath /pathToDatabase/database1 --port 27010
~/installFolder2/mongod --dbpath /pathToDatabase/database2 --port 27011

Related

Start Mongodb server in two modes parallely

I have installed mongo db in my local system, i am aware that at any point in time we can start the mongo using mongod service.
in normal mode which will run on port 27017
in rest API mode where we can query to collections and db's which normally runs on mongo port + 1000
i want to start both mode together, any help would be appreciated.
Thanks
Amit
You should add modify your mongod config file to enable http.
add following config line, see https://docs.mongodb.org/manual/reference/configuration-options/
net:
http:
enabled: true
or add parameter in the command line
mongod --httpinterface
You can start multiple instances of mongod. You just have to make sure that they're using different ports and different dbpaths.
To run two separate instances of mongod
mongod
This will start a mongod instance on port 27017 and use dbpath /data/db
Start another command prompt and type in
mongod --port 27018 --dbpath /data/db2
Just make sure that you have a folder named db2 inside your data folder in your c drive. That's where it stores the data.
Additionally, if you're on Node.js, the MongoDB Node.js driver provides a server method where you can start a mongod instance programatically.
var mongo = require("mongodb");
var server = new mongo.Server('localhost', 27017, { auto_reconnect : true} );
This will create a server in what you are calling the Rest API mode.
And then you can simply start mongod from command prompt specifying some other port and dbpath.
I'm not sure which we can start two instance of mondo or not!. but try this:
Run one of then through service mongod start and second one directly by running binary file (e.g. /usr/bin/mondodb). (also you can run both of them directly from CLI.)
In second mode, you most give appropriate parameter for mondo (e.g. path for config file). If you don't know how to give/pass parameters to mondo's binary file, see man mongodb or go and read /etc/init.d/mongod (in Debian based distributions), it give you useful information)
Unfortunately I don't have an installed mongoDB on my machine, so I can't give you exact commands.

How to get MONGO_URL from command line Meteor Up deployment?

I am currently deploying to Digital Ocean using Meteor Up. If I don't specify a MONGO_URL in the mup.json, can I get the value from the command line while the website is running, i.e. I don't want to shutdown the site?
If I go to the app directory and run meteor mongo --url, I get the following error:
mongo: Meteor isn't running a local MongoDB server.
This command only works while Meteor is running your application
locally. Start your application first. (This error will also occur if
you asked Meteor to use a different MongoDB server with $MONGO_URL when
you ran your application.)
If you're trying to connect to the database of an app you deployed
with 'meteor deploy', specify your site's name with this command.
Even if I run the app from the app directory, it will only give the localhost MONGO_URL. I need the MONGO_URL for the deployed app.
I have also taken a look at a similar question as suggested by some of the answers. I disagree that it is "impossible" to get the MONGO_URL without some other program running on the server. It's not as if we are defying the laws of physics here, folks. Fundamentally, there should be a way to access it. Just because no one has yet figured it out doesn't mean it is impossible.
meteor mongo --url should return the URL.
Try opening another shell in the app directory and running that command.
Meteor Up packages your app in production mode with meteor build so that it runs via node rather than the meteor command line interface. Among other things, this means meteor foo won't work on the remote server (at least not by default). So what you're really looking for is a way to access mongo itself remotely.
I recently set up mongo on an AWS EC2 instance and listed some lessons learned here: https://stackoverflow.com/a/28846703/2669596. Some details of how you do it are going to be different on Digital Ocean, but these are the main things you have to take care of once mongo itself is installed:
Public IP/DNS Address: This is probably fine already since you can deploy to the server.
Port Security Rules: You need to make sure port 27017 is open for TCP access, at least from your IP address. MongoDB also has an http interface you can set up; if you want to use that you'll need to open 28017 as well.
/etc/mongod.conf (file location may differ depending on Linux flavor):
Uncomment port=27017 to make sure you have the default port (I don't think this is actually necessary, but it made me feel better and it's good to know where to change the default port...).
Comment out bind_ip=127.0.0.1 in order to listen to external interfaces (e.g. remote connections).
Uncomment httpinterface=true if you want to use the http interface.
You may have to restart the mongod host via sudo service mongod restart. That's a problem if you can't have downtime, but I don't know of a way around that if you change the config file.
Create User: You need to create an admin and/or user to access the database remotely.
Once you've done all of that, you should be able to access the database from your local machine (assuming you have the mongo client installed locally) by running
mongo server.url.com:27017/mup-app-name -u username -p
where server.url.com is the URL or IP address of your remote server, mup-app-name is the appName parameter from your mup.json file, username is the user you created to access the database, and you'll be prompted for that user's password after you run the command (or you could put it after -p on the same line, depending on the password).
There may also be a way to do this by setting up nginx to reverse-proxy 127.0.0.1:27017 on your remote server, but I've never done it and that's just me speculating.

How run multiple instance of mongodb on the same node using mongodb cookbook?

I am using the mongodb cookbook from edelight/chef-mongodb repo to install multiple instance of mongodb on the same node (OS System: Ubuntu 12.04), but when I follow the file instructions to obtain this goal I can't derive the result expected.
My recipes have only this lines:
include_recipe 'mongodb::10gen_repo'
include_recipe 'mongodb::default'
mongodb_instance "mongodb" do
port 27017
end
mongodb_instance "my_instance" do
port 27333
dbpath "/data/"
end
And the result was one instance of mongodb that is listening by port 27017 and this process configuration is loading from /etc/mongodb.conf. However I need two process, one that is listening from 27017 port and second from 27333.
Does anyone know how this mongodb cookbook can create multiple instances on the same node? or ...is this behavior a new bug to publish as a new Issue on edelight/chef-mongodb repo?

NitrousIO mongodb always connecting to "test" db

I'm trying to setup mongodb on my nitrousio nodejs box. Following this tutorial.
When I finish executing this command,
mongo --shell --host $MONGODB_DEVELOPMENT_HOST --port $MONGODB_DEVELOPMENT_PORT
-u $MONGODB_DEVELOPMENT_USERNAME -p $MONGODB_DEVELOPMENT_PASSWORD
$MONGODB_DEVELOPMENT_DB
This happens,
Even though my MONGO_DEVELOPMENT_DB environment variable is set to pest, it tries to connect to test. Not only pest, if I try to connect to any of my DB instances, it always tries to connect to test.
Any idea as to what could be going wrong?
I had something similar recently and it turned our that the config file was overriding some of the parameters. Try to look at /usr/local/mongodb/mongod.conf (on OS X, probably similar on linux)
Ok, terminated the box and created a new one, that fixed it. Guess I messed up the env. variables in my first attempt. Works just fine now.
I had the same problem and I've tried with new boxes(minimum memory and storage) but it didn't work out.
After increasing memory and storage on existing box to maximum I could
(Memory: 640MB and Storage: 1500MB)
I was able to start MongoDB server and Mongo shell.
After starting the mongo shell your session will use the test database by default. For mong details, please refer to MongoDB Doc
I'm not sure if this will give you everything you need but at least I can ensure the mongo command interface works on Nitrous for me. Firstly a bit of background.
The helpful support guy at Nitrous told me that Nitrous only expose ports: 1024 - 10,000 open. The default for mongodb is: 27017. This port seems to be hand coded into the mongo command as well.
On Nitrous, I changed my mongodb.config file to use a port within that range, on the 0.0.0.0 address:
~/.parts/etc/mongodb.conf
bind_ip = 0.0.0.0
port = 7017
See:
default mongodb ports
config file format
Apparently the bind to 0.0.0.0 IP address is not necessary due to Nitrous magic, however I haven't tested that. After re-starting mongodb server:
$ parts stop mongodb
$ # ... edit ~/.parts/etc/mongodb.conf
$ parts start mongodb
$ mongo localhost:7017
Anyway that works for the default database. I expect other (valid, reasonable) command line options should be OK. The 'test' db name is the default, so if you never make a connection it mongodb probably won't even look at the DB Name given.
I am experimenting with the MEAN.io stack on Nitrous, so the config will be a quite different to your example. That said, this command works fine:
$ mongo localhost:7017/mean-dev
To open the mean-dev database. Hopefully setting the port will give you what is needed.
One last thing the mongodb control interface for that port is on the nitrous preview URL with port number +1,000 ==> 8017. I have not discovered how to make the REST API work with the admin interface (yet). Even so, the admin screen shows me that things are looking reasonable.
Good luck /w.

Is it possible to Set up Master/Slave on the same machine?

I have a question with respect to Mongo DB Master / Slave setup on to the same machine .
I am using Ubutu 12 as OS .
Do i need to have two copies of MongoDB in the same machine ??
If yes , how can it allow to install two times seperately ??
(sudo apt-get install mongodb-10gen)
Since all the linked questions are for Windows and this is a Linux command I will divert from the "Possible duplicate" comment.
Yes you can run multiple mongods on the same machine. Instead of installing multiple times you just start mongod differently like such:
./mongod --dbpath /foo/bar/otherpath --port some_other_port
source: https://serverfault.com/questions/296246/multiple-mongos-on-one-server
But it is not recommended to do this due to resource contention, especially for memory. It will be horrid for even a development server and if you intend to put this setup into production then you might as well just go for one mongod.
If you want to run multiple instances on the same machine it is instead recommended to use containers such as virtual machines or something else. There are a few out there.