V
V
Valeriy Donika2015-10-08 00:13:52
MongoDB
Valeriy Donika, 2015-10-08 00:13:52

How to connect to mongoose in digital ocean?

Hello. I am learning JS stack. I set up a node, express, passport, I already figured out a bit with routing and auth. Now I want to try to save this data in the database. I have not worked with mongodb before, I want to ask how I can connect to it.
First I installed mongodb as it says on the site. mongodbInstall Everything works writes running.
Then I installed mongoose.
In the app.js file I write this

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');

However, the question is, what address to indicate? I follow the example where the author does all this on the local machine. I google this question, someone writes localhost, somewhere localhost: port, someone writes the vps IP address and port.
Moreover, the server port is 3000, but they write another one in mongo.
Plz tell me how to do it right.
Thanks a lot.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
amatory10, 2015-10-08
@Valonix

leave just localhost, mongoose will determine itself, as described here:
mongoosejs.com/docs/connections.html

K
Konstantin Kitmanov, 2015-10-08
@k12th

Moreover, the server port is 3000, but they write another one in mongo.

Of course, a web server on one port, and mongo on another, these are different things. Moreover, it is impossible for two programs to listen to the same port at the same time.
Since you most likely did not configure mongodb, but left everything by default, then your host will be localhost (by default, mongo does not listen to IP calls, only to localhost), and port 27017. That is, now you have everything right. If something does not work, then ask specific questions about what exactly :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question