MongoDB and Deployd - mongodb

Looking to try out Deployd with MongoDB and an AngularJS front end. On my Mac I can get Node and Mongo to launch, but it requires launching mongod with the --config flag. I created a .conf file and launch it with the flag, each time directing it to the location of the .conf file. Deployd is attempting to launch mongodb but gets the same error I got initially trying to start mongod, which is that it can't read the config file.
I'm new to mongo and am having a rough time getting this to play nice. Am I missing something? I even installed it using Homebrew, which was supposed to go ahead and take care of these config issues, but I'm still not getting where I need to be.
Any clarification at this point would be helpful. I'm guessing that there's some simple thing that I've messed up along the way.

I had a similar problem and finally found out how it works.
if you want to use the mongodb dataset which was created by #deployd (you find it in the data folder) tell mongod the path of the folder and the port you want to listen on.
This is how you can start the mongodb server with the deployd dataset
mongod --dbpath ./data/ --port 12345
Next create a node.js script to start deployd which will listen to your mongodb.
var deployd = require('deployd');
var dpd = deployd({
port: 2403,
env: 'development',
db: {
host: '127.0.0.1',
port: 12345,
name: '-deployd'
}
});
dpd.listen();
This script with mongodb will create the exact situation than using the command dpd. However now you can use all other nodejs function.

Related

Problem running meteor locally with a mongodb restored from Atlas snapshot

I want to run a localhost meteor locally to debug using data from production database.
I downloaded a daily snapshot fro Mongo Atlas, extracted it to desktop, unzipped it to a folder called "snap"
Then I run:
mongod --dbpath snap -port 3001
I can see the mongodb now running at 127.0.0.1:3001.
I go to start my meteor project locally:
meteor --settings settings.json
Hoping that it will somehow magically pick up the running database at port 3001, but it didnt.
It complains:
=> Started proxy.
Unexpected mongo exit code 48. Restarting.
=> Meteor 2.1 is available. Update this project with 'meteor update'.
Unexpected mongo exit code 48. Restarting.
Unexpected mongo exit code 48. Restarting.
Can't start Mongo server.
MongoDB exited because its port was closed, or was already
taken by a previous instance of MongoDB
Check for other processes listening on port 3001
or other Meteor instances running in the same project.
What should I do to ask Meteor to start the project using that recovered database?
Assuming your DB is running, you can run locally with your own DB using the environment variable MONGO_URL
$ MONGO_URL=mongodb://localhost:<port>/<dbname> meteor run --settings settings.json
Note, that you need to set an explicit name for the db and if your Meteor db already contains data, then you need to import it into this db in order to have access to both.
Furthermore, I would personally avoid setting port 3001 to not confuse it with the db that is bundled with Meteor. You should be fine with Mongo's defualt 27017 port.
References:
https://docs.meteor.com/environment-variables.html#MONGO-URL

How to login to mongodb console in server

I'm trying to create a new collection in an already existing mongodb database on an ubuntu server. I tried running the command mongod but it says the mongod not found
Make sure your mongo server is running:
you can start using command sudo service mongod restart . Once it started just type mongo , It will take you in mongo console.
Try mongo.
mongod is the one that starts the server. mongo is the client that connects to the server.
If your environment variable is set correctly, it should work.
If it still says command not found, try /usr/bin/mongo
You can find more info here: https://docs.mongodb.com/manual/mongo/

Mongodb is not running

I have installed mongodb in my computer. But whenever I try to launch it, it's not running. I have entered command , as "mongo" to start the mongodb, which shows following resuts, but the application is not opening.
Any one having any idea how can I fix this? Please share it. Thanx!
Environment: Ubuntu 16.04
Those are warnings that appear at the first mongo start. Don't worry to much about them.
Since the process is still running and you got the small > character there, that means you successfully connected to the MongoDB server.
mongod is the MongoDB server (you can check if it's running by running ps aux | grep mongod) and the mongo cli tool is a cli client connecting to the server. Here you can run commands.
For example, create your first document:
use myDatabase
db.people.insert({ name: "Rhea" })
db.people.find()
In conclusion, both the MongoDB server and client are running but you got a few warnings that only appear the first time when you run mongo.
Initially in one terminal write mongod.
Then on another terminal : mongo .
The first one will start the mongo server.
The second one will start the interpreter.
You can try various commands in the interpreter.

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.

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.