Run mongodb from remote server - node.js

I am new to mongodb and want to know about connecting to remote server. I have mongodb running on remote server. I want to access the mongo database from another server and perform all the operation. How can i do that. I am using node.js with mongodb. Please help me how can i establish the connection.

You can use the following library for node:
https://github.com/christkv/node-mongodb-native
If you want a tool to access the database, you can use:
MongoHub (for Mac) & MongoVUE (for Windows)
Good luck!

Related

Can't we use oracle12c instead of mysql in node.js

I have used Oracle 12c instead of mysql.
but I am getting "Error: connect ECONNREFUSED 127.0.0.1:3306"
how to resolve this bug?
Have a look at node-oracledb. Here's a quick start video you can check out too.
Oracle’s network protocol is quite different from MySQL’s, and you can’t use a MySQL client library to connect to an Oracle database. The error message you quote looks like it’s from a MySQL client, since it’s trying port 3306, which is the default port for MySQL. There are Oracle clients for node.js, but I’ve never used any of them and don’t know how good they are.

Procedure for creating a database locally using mongodb

I've connected to mLab using MongoClient.connect, but now I want to create a local database rather than use mLab. I've tried changing the URL to "mongodb://localhost:27017/mydb" to create a database locally as suggested, but I'm getting a failed to connect to server error. Is there anything I should install? Or am I just missing something?
First, install your mongoDB server:
https://docs.mongodb.com/manual/installation/
After that, you should be able to start your local mongodb server:
sudo service mongod start //in case of linux
Here the docs to start the mongodb server
Then, you will type mongo and the client command line will start.
And when typing use yourDatabase, mongo will create the database if
it does not exist.
Then, your server will be up, and the database created. Anyway, check the docs if you need the guides for windows or other systems.
First you need to understand how server works and mlab works. mLab is a company who provide database as a services. Means you no need to handle server hurdles, they take care server , backups , infrastructure etc. They provide mongodb server , You just need to create database on mongodb server's and use them.
Now comes to main points.
If you want use mongodb on your local system then you first need to install mongodb on your local system and then connect it.

Connecting to a mongoDB with a TCP prefix on a NodeJS application

I created a NodeJS app that connects with a MongoDB and it seems to work locally.
Now, after hosting the NodeJS application on a remote machine, I am trying to connect to a mongoDB that was already created on that machine. When I print out some of the environment variables, the only one I see of relevance seems to be :
MONGODB_PORT: 'tcp://172.30.204.90:27017',
I tried connecting like I usually do with
mongoose.connect('mongodb://localhost:27017/metadata/')
and replacing it with mongoose.connect('tcp://172.30.204.90:27017/metadata') but I get an error that says my URI needs to start with 'mongodb'.
So I tried replacing it with mongoose.connect('mongodb://172.30.204.90:27017/metadata') and it no longer throws any error. But on the MongoDB side I don't see any new connections happening and my app does not start up on the machine. What should I be putting in the URI?
Your URI should indeed start with mongodb:
mongoose.connect('mongodb://username:password#host:port/database?options...');
See this page for more information: https://docs.mongodb.com/manual/reference/connection-string/
Did you try to connect to the database from cli? Or Telnet to see that connection isn't blocked.

Storing information in meteor mongodb collection from outside nodejs file

I've got a mongodb collection that gets started with Meteor that I would like to connect to and edit from a nodejs file outside of meteor. From my understanding when I start meteor, I can open another terminal and type meteor mongo and it allows me to connect to the running mongodb instance that meteor is running. But how can I connect to this from a nodejs file? And add items to a collection in a database? What sort of security/authentication do I have to go through if any? (I don't remember having to set up a username/password for the mongodb, it just starts when meteor starts)
When running meteor locally, the mongodb is running on port 3001. There's no security or authentication, you simply have to connect to 127.0.0.1 port 3001, and then access the meteor database.

I want to connect openshift mongodb database from my local client tools

I have my premium openshift account
I have all types of access in openshift
I have ssh key & user's credentials
I have MongoVUE & Robomongo & others client tools to open mongodb database.
when I try to open any local mongodb database then its working fine
but I want to directly connect my mongodb database of openshift server to mongoVUE or any else
so I can see which data is in my server database.
I have tried so many times to connect locally but it can connect to openshift but can not connect with mongodb database so please provide some good & exact steps so I can connect it.
I use mongovue also. Just do a
'rhc port-forward '
Then run mongovue using the Mongodb credentials that OPENSHIFT gave you.
Steps.
rhc port-forward <app-name>
Wait a couple of seconds. You then should see something like this.
Then run Mongovue. Add a connection and enter in your Openshift Mongodb credentials like this:
Save, Select your connection, and press connect. It should work.
You should have been given you mongodb credentials when you added the mongodb cartridge. You can also ssh into your app and do a "env" and see your mongodb password and username.
Finally I got perfect tool for it to connect with mongodb with server database in which we can perform all kind of CRUD operations.
we can use Robomongo tool for it which doesn't require paid version to perform CRUD operation.
Robomongo is available here
http://robomongo.org/download.html
mongoVUE requires paid version.
I use Robomongo. Just do a 'rhc port-forward '
Then run Robomongo using the Mongodb credentials that OPENSHIFT gave you.
Steps.
rhc port-forward
Wait a couple of seconds. You then should see something like this.
port forward image
Then run Robomongo. Add a connection and enter in your Openshift Mongodb credentials:

Resources