Procedure for creating a database locally using mongodb - node.js

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.

Related

MongoDb in Fastcomet shared hosting server

I haven't created an account in fastcomet yet, but I would like to ask the following questions. The site mentions that it supports node.js applications. So that means I can upload an express application right? How about MongoDB and mongoose? I can access MongoDB by typing in the terminal
$ mongod --dbpath=data -bind_ip 127.0.0.1
And the MongoDB URL in my case is
mongodb://localhost:27017/ilovearisti
How different would it be in fastcommet? I guess I'll have to contact them for the port numbers right?
Thanks,
Theo.
FastComet Team here! Indeed, our hosting plans are fully compatible with Node.js apps and you can have your project hosted on an appropriate package.
If you plan using the MongoDB database type in particular, our experience shows it requires a server solution with more resources and a higher level of private access. This way you would be able to accommodate the operation on an environment suitable for coding with Mongoose on top of the MongoDB driver for Node.js.
As for addressing your URL query, the default IP when starting a mongo instance is set to 127.0.0.1, so it is configured as localhost and port 27017. With this in mind, you only need to make changes on the IP configuration via the mongod daemon if you are using a remote database setup with a different IP address.
Having said all of the above, we can confirm that if you have created a database called iloveiristi, the MongoDB URL will be as follows:
mongodb://localhost:27017/iloveiristi
We hope this information proves useful and we wish you good luck with your project.
Best regards!

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.

database settings in reactioncommerce

I installed reactioncommerce and I would like to access the database settings to check the name that the installation created in my mongodb server. I checked the information on the website but I cannot find any details about it.
in mongodb: when I use "show dbs" in mongo I cannot see any new db in my server. on the other hand, the demo application is running on port localhost:3000.
any guidance appreciated.
well it seems the mongodb for meteor always runs at one port above the meteor port. So by default the db is running at 3001. While you can have Meteor running you can also run meteor mongo and get a db console that way.

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:

Run mongodb from remote server

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!

Resources