Timeout when trying to access MongoDB
Upfront: I'm using [Digital Ocean, Rancher, Docker, NodeJS, Mongoose].
Hey everyone,
I followed this article/tutorial about setting up a Docker environment using Rancher:
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-node-js-and-mongodb-application-with-rancher-on-ubuntu-16-04
The main differences are that I'm using Mongoose
and Express
instead.
Everything works as expected on the Rancher side; I'm able to scale DBs, Node droplets, etc.
However, connecting to MongoDB from JS seems to not be working.
If I hit /
on the server, I get my static 'Hello, world!' test message. However if I hit a route that resolves to a controller method that tries to access MongoDB, I hang for a while until I eventually get a 504 Timeout
.
I have confirmed that my MONGO_HOST
environment property is being correctly.
I have also confirmed that the MongoDB host is reachable from the IP address specified in Rancher, via ping
. If I try to ping
that IP from outside the network, it's unreachable, which is expected.
In my server.js
file I have the following to connect to Mongo:
mongoose.connect('mongodb://' + process.env.MONGO_HOST + '/api', { useNewUrlParser: true });
In Rancher, my NodeJS application service is linked to my MongoDB service.
Locally when I launch the Mongo container and my application container, it works fine. The database has no data in it yet so the response of is valid. This is what I expect to see when accessing the production version, but instead it just times out.
Anyone have any insights as to why this might happen? My gut tells me port mapping of some kind, but the guide doesn't mention anything about that in the remote container / Rancher setup.
Update 1:
Adding some code from the controller where Mongo is used.
'use strict';
var mongoose = require('mongoose'),
Event = mongoose.model('Events');
exports.list_all_events = function(req, res) {
Event.find({}, function(err, event) {
if (err)
res.send(err);
res.json(event);
});
};
node.js mongodb digital-ocean rancher
add a comment |
Upfront: I'm using [Digital Ocean, Rancher, Docker, NodeJS, Mongoose].
Hey everyone,
I followed this article/tutorial about setting up a Docker environment using Rancher:
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-node-js-and-mongodb-application-with-rancher-on-ubuntu-16-04
The main differences are that I'm using Mongoose
and Express
instead.
Everything works as expected on the Rancher side; I'm able to scale DBs, Node droplets, etc.
However, connecting to MongoDB from JS seems to not be working.
If I hit /
on the server, I get my static 'Hello, world!' test message. However if I hit a route that resolves to a controller method that tries to access MongoDB, I hang for a while until I eventually get a 504 Timeout
.
I have confirmed that my MONGO_HOST
environment property is being correctly.
I have also confirmed that the MongoDB host is reachable from the IP address specified in Rancher, via ping
. If I try to ping
that IP from outside the network, it's unreachable, which is expected.
In my server.js
file I have the following to connect to Mongo:
mongoose.connect('mongodb://' + process.env.MONGO_HOST + '/api', { useNewUrlParser: true });
In Rancher, my NodeJS application service is linked to my MongoDB service.
Locally when I launch the Mongo container and my application container, it works fine. The database has no data in it yet so the response of is valid. This is what I expect to see when accessing the production version, but instead it just times out.
Anyone have any insights as to why this might happen? My gut tells me port mapping of some kind, but the guide doesn't mention anything about that in the remote container / Rancher setup.
Update 1:
Adding some code from the controller where Mongo is used.
'use strict';
var mongoose = require('mongoose'),
Event = mongoose.model('Events');
exports.list_all_events = function(req, res) {
Event.find({}, function(err, event) {
if (err)
res.send(err);
res.json(event);
});
};
node.js mongodb digital-ocean rancher
Can you please add the source code of your controller where you are getting the 504 error? Along with that, if you have doubt on MongoDB connectivity then add following events to check the connectivity mongoose.connection.on('connected', () => { console.log('database connected'); }); mongoose.connection.on('error', (err) => { console.error(err); });
– Amolpskamble
Nov 24 '18 at 20:51
@Amolpskamble, I've updated my question with some code from the controller where Mongo is being used.
– matcartmill
Nov 24 '18 at 22:32
@Amolpskamble I was able to log the error that happens at connection time: "{"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]}"
– matcartmill
Nov 25 '18 at 1:38
add a comment |
Upfront: I'm using [Digital Ocean, Rancher, Docker, NodeJS, Mongoose].
Hey everyone,
I followed this article/tutorial about setting up a Docker environment using Rancher:
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-node-js-and-mongodb-application-with-rancher-on-ubuntu-16-04
The main differences are that I'm using Mongoose
and Express
instead.
Everything works as expected on the Rancher side; I'm able to scale DBs, Node droplets, etc.
However, connecting to MongoDB from JS seems to not be working.
If I hit /
on the server, I get my static 'Hello, world!' test message. However if I hit a route that resolves to a controller method that tries to access MongoDB, I hang for a while until I eventually get a 504 Timeout
.
I have confirmed that my MONGO_HOST
environment property is being correctly.
I have also confirmed that the MongoDB host is reachable from the IP address specified in Rancher, via ping
. If I try to ping
that IP from outside the network, it's unreachable, which is expected.
In my server.js
file I have the following to connect to Mongo:
mongoose.connect('mongodb://' + process.env.MONGO_HOST + '/api', { useNewUrlParser: true });
In Rancher, my NodeJS application service is linked to my MongoDB service.
Locally when I launch the Mongo container and my application container, it works fine. The database has no data in it yet so the response of is valid. This is what I expect to see when accessing the production version, but instead it just times out.
Anyone have any insights as to why this might happen? My gut tells me port mapping of some kind, but the guide doesn't mention anything about that in the remote container / Rancher setup.
Update 1:
Adding some code from the controller where Mongo is used.
'use strict';
var mongoose = require('mongoose'),
Event = mongoose.model('Events');
exports.list_all_events = function(req, res) {
Event.find({}, function(err, event) {
if (err)
res.send(err);
res.json(event);
});
};
node.js mongodb digital-ocean rancher
Upfront: I'm using [Digital Ocean, Rancher, Docker, NodeJS, Mongoose].
Hey everyone,
I followed this article/tutorial about setting up a Docker environment using Rancher:
https://www.digitalocean.com/community/tutorials/how-to-deploy-a-node-js-and-mongodb-application-with-rancher-on-ubuntu-16-04
The main differences are that I'm using Mongoose
and Express
instead.
Everything works as expected on the Rancher side; I'm able to scale DBs, Node droplets, etc.
However, connecting to MongoDB from JS seems to not be working.
If I hit /
on the server, I get my static 'Hello, world!' test message. However if I hit a route that resolves to a controller method that tries to access MongoDB, I hang for a while until I eventually get a 504 Timeout
.
I have confirmed that my MONGO_HOST
environment property is being correctly.
I have also confirmed that the MongoDB host is reachable from the IP address specified in Rancher, via ping
. If I try to ping
that IP from outside the network, it's unreachable, which is expected.
In my server.js
file I have the following to connect to Mongo:
mongoose.connect('mongodb://' + process.env.MONGO_HOST + '/api', { useNewUrlParser: true });
In Rancher, my NodeJS application service is linked to my MongoDB service.
Locally when I launch the Mongo container and my application container, it works fine. The database has no data in it yet so the response of is valid. This is what I expect to see when accessing the production version, but instead it just times out.
Anyone have any insights as to why this might happen? My gut tells me port mapping of some kind, but the guide doesn't mention anything about that in the remote container / Rancher setup.
Update 1:
Adding some code from the controller where Mongo is used.
'use strict';
var mongoose = require('mongoose'),
Event = mongoose.model('Events');
exports.list_all_events = function(req, res) {
Event.find({}, function(err, event) {
if (err)
res.send(err);
res.json(event);
});
};
node.js mongodb digital-ocean rancher
node.js mongodb digital-ocean rancher
edited Nov 24 '18 at 22:33
matcartmill
asked Nov 24 '18 at 14:26
matcartmillmatcartmill
74621131
74621131
Can you please add the source code of your controller where you are getting the 504 error? Along with that, if you have doubt on MongoDB connectivity then add following events to check the connectivity mongoose.connection.on('connected', () => { console.log('database connected'); }); mongoose.connection.on('error', (err) => { console.error(err); });
– Amolpskamble
Nov 24 '18 at 20:51
@Amolpskamble, I've updated my question with some code from the controller where Mongo is being used.
– matcartmill
Nov 24 '18 at 22:32
@Amolpskamble I was able to log the error that happens at connection time: "{"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]}"
– matcartmill
Nov 25 '18 at 1:38
add a comment |
Can you please add the source code of your controller where you are getting the 504 error? Along with that, if you have doubt on MongoDB connectivity then add following events to check the connectivity mongoose.connection.on('connected', () => { console.log('database connected'); }); mongoose.connection.on('error', (err) => { console.error(err); });
– Amolpskamble
Nov 24 '18 at 20:51
@Amolpskamble, I've updated my question with some code from the controller where Mongo is being used.
– matcartmill
Nov 24 '18 at 22:32
@Amolpskamble I was able to log the error that happens at connection time: "{"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]}"
– matcartmill
Nov 25 '18 at 1:38
Can you please add the source code of your controller where you are getting the 504 error? Along with that, if you have doubt on MongoDB connectivity then add following events to check the connectivity mongoose.connection.on('connected', () => { console.log('database connected'); }); mongoose.connection.on('error', (err) => { console.error(err); });
– Amolpskamble
Nov 24 '18 at 20:51
Can you please add the source code of your controller where you are getting the 504 error? Along with that, if you have doubt on MongoDB connectivity then add following events to check the connectivity mongoose.connection.on('connected', () => { console.log('database connected'); }); mongoose.connection.on('error', (err) => { console.error(err); });
– Amolpskamble
Nov 24 '18 at 20:51
@Amolpskamble, I've updated my question with some code from the controller where Mongo is being used.
– matcartmill
Nov 24 '18 at 22:32
@Amolpskamble, I've updated my question with some code from the controller where Mongo is being used.
– matcartmill
Nov 24 '18 at 22:32
@Amolpskamble I was able to log the error that happens at connection time: "{"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]}"
– matcartmill
Nov 25 '18 at 1:38
@Amolpskamble I was able to log the error that happens at connection time: "{"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]}"
– matcartmill
Nov 25 '18 at 1:38
add a comment |
1 Answer
1
active
oldest
votes
I was able to resolve this issue by setting the As name
parameter when linking the Mongo
service to the NodeJS
service. This is explained in the tutorial, but I missed it the first few times around.
I've included a screenshot of the section where this is set in case anyone else gets stumped by this.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459143%2ftimeout-when-trying-to-access-mongodb%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I was able to resolve this issue by setting the As name
parameter when linking the Mongo
service to the NodeJS
service. This is explained in the tutorial, but I missed it the first few times around.
I've included a screenshot of the section where this is set in case anyone else gets stumped by this.
add a comment |
I was able to resolve this issue by setting the As name
parameter when linking the Mongo
service to the NodeJS
service. This is explained in the tutorial, but I missed it the first few times around.
I've included a screenshot of the section where this is set in case anyone else gets stumped by this.
add a comment |
I was able to resolve this issue by setting the As name
parameter when linking the Mongo
service to the NodeJS
service. This is explained in the tutorial, but I missed it the first few times around.
I've included a screenshot of the section where this is set in case anyone else gets stumped by this.
I was able to resolve this issue by setting the As name
parameter when linking the Mongo
service to the NodeJS
service. This is explained in the tutorial, but I missed it the first few times around.
I've included a screenshot of the section where this is set in case anyone else gets stumped by this.
answered Nov 25 '18 at 3:53
matcartmillmatcartmill
74621131
74621131
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53459143%2ftimeout-when-trying-to-access-mongodb%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Can you please add the source code of your controller where you are getting the 504 error? Along with that, if you have doubt on MongoDB connectivity then add following events to check the connectivity mongoose.connection.on('connected', () => { console.log('database connected'); }); mongoose.connection.on('error', (err) => { console.error(err); });
– Amolpskamble
Nov 24 '18 at 20:51
@Amolpskamble, I've updated my question with some code from the controller where Mongo is being used.
– matcartmill
Nov 24 '18 at 22:32
@Amolpskamble I was able to log the error that happens at connection time: "{"name":"MongoNetworkError","errorLabels":["TransientTransactionError"]}"
– matcartmill
Nov 25 '18 at 1:38