Mongoose MongoNetworkError // connection error
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have a problem with connection to mongoose.
I'm trying to connect to mongoDB atlas and getting MongoNetworkError.
That's my code and error log.
Thank you for a help.
const express = require('express');
const app = express();
const morgan = require('morgan');
const bodyParser =require('body-parser');
const mongoose = require('mongoose');
const productRoutes = require('./api/routes/products');
const ordersRoutes = require('./api/routes/orders');
mongoose.connect('mongodb://robertRobot:robertRobot@nodeshop-shard-00-00-5oqzt.mongodb.net:27017,nodeshop-shard-00-01-5oqzt.mongodb.net:27017,nodeshop-shard-00-02-5oqzt.mongodb.net:27017/test?ssl=true&replicaSet=NodeShop-shard-0&authSource=admin&retryWrites=true',
{ useNewUrlParser: true }
).then().catch(err=>{
console.log('xxxxxxxxxxxxxxxxxxxxxx');
console.log(err);
});
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.use((req,re,next)=>{
res.header('access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Autorisation');
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow', 'PUT, POST, PATCH, DELETE, GET');
return res.status(200).json({});
next();
}
});
app.use('/products', productRoutes);
app.use('/orders', ordersRoutes);
app.use((req, res,next)=>{
const error = new Error('not found');
error.status = 404;
next(error);
});
app.use((error, req, res, next)=>{
res.status(error.status || 500);
res.json({
error: {
message : '500 error'
}
});
});
module.exports = app;
Error log:
{ MongoNetworkError: connection 4 to nodeshop-shard-00-02-5oqzt.mongodb.net:27017 closed
at TLSSocket.<anonymous> (/Users/robertas/Desktop/node-js/restApi/node_modules/mongodb-core/lib/connection/connection.js:276:9)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:121:20)
at TLSSocket.emit (events.js:211:7)
at _handle.close (net.js:561:12)
at TCP.done [as _onclose] (_tls_wrap.js:360:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
javascript node.js mongodb mongoose
add a comment |
I have a problem with connection to mongoose.
I'm trying to connect to mongoDB atlas and getting MongoNetworkError.
That's my code and error log.
Thank you for a help.
const express = require('express');
const app = express();
const morgan = require('morgan');
const bodyParser =require('body-parser');
const mongoose = require('mongoose');
const productRoutes = require('./api/routes/products');
const ordersRoutes = require('./api/routes/orders');
mongoose.connect('mongodb://robertRobot:robertRobot@nodeshop-shard-00-00-5oqzt.mongodb.net:27017,nodeshop-shard-00-01-5oqzt.mongodb.net:27017,nodeshop-shard-00-02-5oqzt.mongodb.net:27017/test?ssl=true&replicaSet=NodeShop-shard-0&authSource=admin&retryWrites=true',
{ useNewUrlParser: true }
).then().catch(err=>{
console.log('xxxxxxxxxxxxxxxxxxxxxx');
console.log(err);
});
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.use((req,re,next)=>{
res.header('access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Autorisation');
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow', 'PUT, POST, PATCH, DELETE, GET');
return res.status(200).json({});
next();
}
});
app.use('/products', productRoutes);
app.use('/orders', ordersRoutes);
app.use((req, res,next)=>{
const error = new Error('not found');
error.status = 404;
next(error);
});
app.use((error, req, res, next)=>{
res.status(error.status || 500);
res.json({
error: {
message : '500 error'
}
});
});
module.exports = app;
Error log:
{ MongoNetworkError: connection 4 to nodeshop-shard-00-02-5oqzt.mongodb.net:27017 closed
at TLSSocket.<anonymous> (/Users/robertas/Desktop/node-js/restApi/node_modules/mongodb-core/lib/connection/connection.js:276:9)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:121:20)
at TLSSocket.emit (events.js:211:7)
at _handle.close (net.js:561:12)
at TCP.done [as _onclose] (_tls_wrap.js:360:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
javascript node.js mongodb mongoose
Is there some reason why you are using the old style URI and not themongodb+srvURI? Have you checked that you can reach the hosts from your PC or wherever the application is running?
– Neil Lunn
Nov 23 '18 at 11:37
I replaced uri to mongodb+srv but got the same error
– Robertas Ankudovicius
Nov 23 '18 at 11:41
Check your networking connections first, since that's the priorty here. A network error basically means "I can't find anything there". Usually because it's unreachable from where you are trying to reach it from.
– Neil Lunn
Nov 23 '18 at 11:44
add a comment |
I have a problem with connection to mongoose.
I'm trying to connect to mongoDB atlas and getting MongoNetworkError.
That's my code and error log.
Thank you for a help.
const express = require('express');
const app = express();
const morgan = require('morgan');
const bodyParser =require('body-parser');
const mongoose = require('mongoose');
const productRoutes = require('./api/routes/products');
const ordersRoutes = require('./api/routes/orders');
mongoose.connect('mongodb://robertRobot:robertRobot@nodeshop-shard-00-00-5oqzt.mongodb.net:27017,nodeshop-shard-00-01-5oqzt.mongodb.net:27017,nodeshop-shard-00-02-5oqzt.mongodb.net:27017/test?ssl=true&replicaSet=NodeShop-shard-0&authSource=admin&retryWrites=true',
{ useNewUrlParser: true }
).then().catch(err=>{
console.log('xxxxxxxxxxxxxxxxxxxxxx');
console.log(err);
});
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.use((req,re,next)=>{
res.header('access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Autorisation');
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow', 'PUT, POST, PATCH, DELETE, GET');
return res.status(200).json({});
next();
}
});
app.use('/products', productRoutes);
app.use('/orders', ordersRoutes);
app.use((req, res,next)=>{
const error = new Error('not found');
error.status = 404;
next(error);
});
app.use((error, req, res, next)=>{
res.status(error.status || 500);
res.json({
error: {
message : '500 error'
}
});
});
module.exports = app;
Error log:
{ MongoNetworkError: connection 4 to nodeshop-shard-00-02-5oqzt.mongodb.net:27017 closed
at TLSSocket.<anonymous> (/Users/robertas/Desktop/node-js/restApi/node_modules/mongodb-core/lib/connection/connection.js:276:9)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:121:20)
at TLSSocket.emit (events.js:211:7)
at _handle.close (net.js:561:12)
at TCP.done [as _onclose] (_tls_wrap.js:360:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
javascript node.js mongodb mongoose
I have a problem with connection to mongoose.
I'm trying to connect to mongoDB atlas and getting MongoNetworkError.
That's my code and error log.
Thank you for a help.
const express = require('express');
const app = express();
const morgan = require('morgan');
const bodyParser =require('body-parser');
const mongoose = require('mongoose');
const productRoutes = require('./api/routes/products');
const ordersRoutes = require('./api/routes/orders');
mongoose.connect('mongodb://robertRobot:robertRobot@nodeshop-shard-00-00-5oqzt.mongodb.net:27017,nodeshop-shard-00-01-5oqzt.mongodb.net:27017,nodeshop-shard-00-02-5oqzt.mongodb.net:27017/test?ssl=true&replicaSet=NodeShop-shard-0&authSource=admin&retryWrites=true',
{ useNewUrlParser: true }
).then().catch(err=>{
console.log('xxxxxxxxxxxxxxxxxxxxxx');
console.log(err);
});
app.use(morgan('dev'));
app.use(bodyParser.urlencoded({extended : false}));
app.use(bodyParser.json());
app.use((req,re,next)=>{
res.header('access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Autorisation');
if (req.method === 'OPTIONS') {
res.header('Access-Control-Allow', 'PUT, POST, PATCH, DELETE, GET');
return res.status(200).json({});
next();
}
});
app.use('/products', productRoutes);
app.use('/orders', ordersRoutes);
app.use((req, res,next)=>{
const error = new Error('not found');
error.status = 404;
next(error);
});
app.use((error, req, res, next)=>{
res.status(error.status || 500);
res.json({
error: {
message : '500 error'
}
});
});
module.exports = app;
Error log:
{ MongoNetworkError: connection 4 to nodeshop-shard-00-02-5oqzt.mongodb.net:27017 closed
at TLSSocket.<anonymous> (/Users/robertas/Desktop/node-js/restApi/node_modules/mongodb-core/lib/connection/connection.js:276:9)
at Object.onceWrapper (events.js:315:30)
at emitOne (events.js:121:20)
at TLSSocket.emit (events.js:211:7)
at _handle.close (net.js:561:12)
at TCP.done [as _onclose] (_tls_wrap.js:360:7)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
javascript node.js mongodb mongoose
javascript node.js mongodb mongoose
edited Nov 23 '18 at 11:35
Neil Lunn
101k23179187
101k23179187
asked Nov 23 '18 at 11:31
Robertas AnkudoviciusRobertas Ankudovicius
185
185
Is there some reason why you are using the old style URI and not themongodb+srvURI? Have you checked that you can reach the hosts from your PC or wherever the application is running?
– Neil Lunn
Nov 23 '18 at 11:37
I replaced uri to mongodb+srv but got the same error
– Robertas Ankudovicius
Nov 23 '18 at 11:41
Check your networking connections first, since that's the priorty here. A network error basically means "I can't find anything there". Usually because it's unreachable from where you are trying to reach it from.
– Neil Lunn
Nov 23 '18 at 11:44
add a comment |
Is there some reason why you are using the old style URI and not themongodb+srvURI? Have you checked that you can reach the hosts from your PC or wherever the application is running?
– Neil Lunn
Nov 23 '18 at 11:37
I replaced uri to mongodb+srv but got the same error
– Robertas Ankudovicius
Nov 23 '18 at 11:41
Check your networking connections first, since that's the priorty here. A network error basically means "I can't find anything there". Usually because it's unreachable from where you are trying to reach it from.
– Neil Lunn
Nov 23 '18 at 11:44
Is there some reason why you are using the old style URI and not the
mongodb+srv URI? Have you checked that you can reach the hosts from your PC or wherever the application is running?– Neil Lunn
Nov 23 '18 at 11:37
Is there some reason why you are using the old style URI and not the
mongodb+srv URI? Have you checked that you can reach the hosts from your PC or wherever the application is running?– Neil Lunn
Nov 23 '18 at 11:37
I replaced uri to mongodb+srv but got the same error
– Robertas Ankudovicius
Nov 23 '18 at 11:41
I replaced uri to mongodb+srv but got the same error
– Robertas Ankudovicius
Nov 23 '18 at 11:41
Check your networking connections first, since that's the priorty here. A network error basically means "I can't find anything there". Usually because it's unreachable from where you are trying to reach it from.
– Neil Lunn
Nov 23 '18 at 11:44
Check your networking connections first, since that's the priorty here. A network error basically means "I can't find anything there". Usually because it's unreachable from where you are trying to reach it from.
– Neil Lunn
Nov 23 '18 at 11:44
add a comment |
1 Answer
1
active
oldest
votes
restart your mongodb. If using linux then try is command:
sudo service mongod start
Also, just give mongo in mongo shell and check wheather its working.
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%2f53445896%2fmongoose-mongonetworkerror-connection-error%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
restart your mongodb. If using linux then try is command:
sudo service mongod start
Also, just give mongo in mongo shell and check wheather its working.
add a comment |
restart your mongodb. If using linux then try is command:
sudo service mongod start
Also, just give mongo in mongo shell and check wheather its working.
add a comment |
restart your mongodb. If using linux then try is command:
sudo service mongod start
Also, just give mongo in mongo shell and check wheather its working.
restart your mongodb. If using linux then try is command:
sudo service mongod start
Also, just give mongo in mongo shell and check wheather its working.
answered Nov 24 '18 at 15:55
Raunik SinghRaunik Singh
1094
1094
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%2f53445896%2fmongoose-mongonetworkerror-connection-error%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
Is there some reason why you are using the old style URI and not the
mongodb+srvURI? Have you checked that you can reach the hosts from your PC or wherever the application is running?– Neil Lunn
Nov 23 '18 at 11:37
I replaced uri to mongodb+srv but got the same error
– Robertas Ankudovicius
Nov 23 '18 at 11:41
Check your networking connections first, since that's the priorty here. A network error basically means "I can't find anything there". Usually because it's unreachable from where you are trying to reach it from.
– Neil Lunn
Nov 23 '18 at 11:44