Cannot connect to MongoDB from Node.js
up vote
0
down vote
favorite
I am trying to make a connection to my MongoDB database but I get the following error message:
AssertionError
actual: null
expected: RangeError: Maximum call stack size exceeded at isUndefined (<anonymous>:2748:21) at Object.exports.deprecate (<anonymous>:2330:7) at <anonymous>:2332:22 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41
generatedMessage: true
message: "null == [RangeError: Maximum call stack size exceeded]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [RangeError: Maximum call stack size exceeded]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error
constructor: ƒ AssertionError(options)
__proto__: Object
Maybe you would reprobate me for not having checked and reused previous topics. But despite the similarity of the problem, none of them matches with my case.
For the connection, I am following this tutorial: http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/ (look at "Connect to MongoDB"):
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
// Connection URL
const url = "mongodb://secretoes:thatstotallysecret@mudfeval-shard-00-00-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-01-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-02-uxnqk.gcp.mongodb.net:27017/test?ssl=true&replicaSet=mudfeval-shard-0&authSource=admin&retryWrites=true";;
// Database Name
const dbName = 'moodle';
// Create a new MongoClient
const client = new MongoClient(url);
// Use connect method to connect to the Server
client.connect(function(err) {
assert.equal(null, err);
console.log("Connected successfully to server");
const db = client.db(dbName);
client.close();
});
Once said that, could somebody help me? I cannot find out anything anywhere. I am puzzled.
=============
UPDATE (11/8/2018 - 01:11 pm UTC+1)
If I run the script through console, I get no problem. However I receive a deprecation warning that asked me to use the new parser.
So, when I run it on web browser after those changes, the error message is the following:
VM188:1932 Uncaught
AssertionError {name: "AssertionError", actual: null, expected: TypeError: qs.unescape is not a function
at parseConnectionString (<anonymous>:52229:75)
at …, operator: "==", message: "null == [TypeError: qs.unescape is not a function]", …}
actual: null
expected: TypeError: qs.unescape is not a function at parseConnectionString (<anonymous>:52229:75) at connect (<anonymous>:68112:3) at connectOp (<anonymous>:68216:3) at executeOperation (<anonymous>:71488:24) at MongoClient.connect (<anonymous>:64885:10) at Object.274.assert (<anonymous>:73718:8) at o (<anonymous>:1:265) at r (<anonymous>:1:431) at <anonymous>:1:460 at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)
generatedMessage: true
message: "null == [TypeError: qs.unescape is not a function]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [TypeError: qs.unescape is not a function]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error
Is it because of browserify?
javascript node.js mongodb
|
show 11 more comments
up vote
0
down vote
favorite
I am trying to make a connection to my MongoDB database but I get the following error message:
AssertionError
actual: null
expected: RangeError: Maximum call stack size exceeded at isUndefined (<anonymous>:2748:21) at Object.exports.deprecate (<anonymous>:2330:7) at <anonymous>:2332:22 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41
generatedMessage: true
message: "null == [RangeError: Maximum call stack size exceeded]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [RangeError: Maximum call stack size exceeded]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error
constructor: ƒ AssertionError(options)
__proto__: Object
Maybe you would reprobate me for not having checked and reused previous topics. But despite the similarity of the problem, none of them matches with my case.
For the connection, I am following this tutorial: http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/ (look at "Connect to MongoDB"):
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
// Connection URL
const url = "mongodb://secretoes:thatstotallysecret@mudfeval-shard-00-00-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-01-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-02-uxnqk.gcp.mongodb.net:27017/test?ssl=true&replicaSet=mudfeval-shard-0&authSource=admin&retryWrites=true";;
// Database Name
const dbName = 'moodle';
// Create a new MongoClient
const client = new MongoClient(url);
// Use connect method to connect to the Server
client.connect(function(err) {
assert.equal(null, err);
console.log("Connected successfully to server");
const db = client.db(dbName);
client.close();
});
Once said that, could somebody help me? I cannot find out anything anywhere. I am puzzled.
=============
UPDATE (11/8/2018 - 01:11 pm UTC+1)
If I run the script through console, I get no problem. However I receive a deprecation warning that asked me to use the new parser.
So, when I run it on web browser after those changes, the error message is the following:
VM188:1932 Uncaught
AssertionError {name: "AssertionError", actual: null, expected: TypeError: qs.unescape is not a function
at parseConnectionString (<anonymous>:52229:75)
at …, operator: "==", message: "null == [TypeError: qs.unescape is not a function]", …}
actual: null
expected: TypeError: qs.unescape is not a function at parseConnectionString (<anonymous>:52229:75) at connect (<anonymous>:68112:3) at connectOp (<anonymous>:68216:3) at executeOperation (<anonymous>:71488:24) at MongoClient.connect (<anonymous>:64885:10) at Object.274.assert (<anonymous>:73718:8) at o (<anonymous>:1:265) at r (<anonymous>:1:431) at <anonymous>:1:460 at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)
generatedMessage: true
message: "null == [TypeError: qs.unescape is not a function]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [TypeError: qs.unescape is not a function]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error
Is it because of browserify?
javascript node.js mongodb
This could be because you create a new connection every time when you need it. If this is the case, the problem isn't with the code what you pasted (it seems fine to me), but the number of the times when you import it from your routes for example. The solution would be to initiate one connection only and share it across the whole server.
– lependu
Nov 8 at 9:18
It cannot be the case because sometimes I have created PHP applications that call different times the correspondant functions to connect to the server sucessfully, @lependu.
– Ciconia Grullera
Nov 8 at 9:27
What node version are you using? Are you seeing Connected successfully to server being logged or do you get the error on first connect try?
– n32303
Nov 8 at 10:29
According to npm, 3.10.10 version, @n32303. On the other hand I get the error on first connect attempt.
– Ciconia Grullera
Nov 8 at 10:32
That's probably npm version. Can you try executing 'node -v' ?
– n32303
Nov 8 at 10:33
|
show 11 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am trying to make a connection to my MongoDB database but I get the following error message:
AssertionError
actual: null
expected: RangeError: Maximum call stack size exceeded at isUndefined (<anonymous>:2748:21) at Object.exports.deprecate (<anonymous>:2330:7) at <anonymous>:2332:22 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41
generatedMessage: true
message: "null == [RangeError: Maximum call stack size exceeded]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [RangeError: Maximum call stack size exceeded]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error
constructor: ƒ AssertionError(options)
__proto__: Object
Maybe you would reprobate me for not having checked and reused previous topics. But despite the similarity of the problem, none of them matches with my case.
For the connection, I am following this tutorial: http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/ (look at "Connect to MongoDB"):
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
// Connection URL
const url = "mongodb://secretoes:thatstotallysecret@mudfeval-shard-00-00-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-01-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-02-uxnqk.gcp.mongodb.net:27017/test?ssl=true&replicaSet=mudfeval-shard-0&authSource=admin&retryWrites=true";;
// Database Name
const dbName = 'moodle';
// Create a new MongoClient
const client = new MongoClient(url);
// Use connect method to connect to the Server
client.connect(function(err) {
assert.equal(null, err);
console.log("Connected successfully to server");
const db = client.db(dbName);
client.close();
});
Once said that, could somebody help me? I cannot find out anything anywhere. I am puzzled.
=============
UPDATE (11/8/2018 - 01:11 pm UTC+1)
If I run the script through console, I get no problem. However I receive a deprecation warning that asked me to use the new parser.
So, when I run it on web browser after those changes, the error message is the following:
VM188:1932 Uncaught
AssertionError {name: "AssertionError", actual: null, expected: TypeError: qs.unescape is not a function
at parseConnectionString (<anonymous>:52229:75)
at …, operator: "==", message: "null == [TypeError: qs.unescape is not a function]", …}
actual: null
expected: TypeError: qs.unescape is not a function at parseConnectionString (<anonymous>:52229:75) at connect (<anonymous>:68112:3) at connectOp (<anonymous>:68216:3) at executeOperation (<anonymous>:71488:24) at MongoClient.connect (<anonymous>:64885:10) at Object.274.assert (<anonymous>:73718:8) at o (<anonymous>:1:265) at r (<anonymous>:1:431) at <anonymous>:1:460 at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)
generatedMessage: true
message: "null == [TypeError: qs.unescape is not a function]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [TypeError: qs.unescape is not a function]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error
Is it because of browserify?
javascript node.js mongodb
I am trying to make a connection to my MongoDB database but I get the following error message:
AssertionError
actual: null
expected: RangeError: Maximum call stack size exceeded at isUndefined (<anonymous>:2748:21) at Object.exports.deprecate (<anonymous>:2330:7) at <anonymous>:2332:22 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41 at <anonymous>:2332:41
generatedMessage: true
message: "null == [RangeError: Maximum call stack size exceeded]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [RangeError: Maximum call stack size exceeded]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error
constructor: ƒ AssertionError(options)
__proto__: Object
Maybe you would reprobate me for not having checked and reused previous topics. But despite the similarity of the problem, none of them matches with my case.
For the connection, I am following this tutorial: http://mongodb.github.io/node-mongodb-native/3.1/quick-start/quick-start/ (look at "Connect to MongoDB"):
const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');
// Connection URL
const url = "mongodb://secretoes:thatstotallysecret@mudfeval-shard-00-00-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-01-uxnqk.gcp.mongodb.net:27017,mudfeval-shard-00-02-uxnqk.gcp.mongodb.net:27017/test?ssl=true&replicaSet=mudfeval-shard-0&authSource=admin&retryWrites=true";;
// Database Name
const dbName = 'moodle';
// Create a new MongoClient
const client = new MongoClient(url);
// Use connect method to connect to the Server
client.connect(function(err) {
assert.equal(null, err);
console.log("Connected successfully to server");
const db = client.db(dbName);
client.close();
});
Once said that, could somebody help me? I cannot find out anything anywhere. I am puzzled.
=============
UPDATE (11/8/2018 - 01:11 pm UTC+1)
If I run the script through console, I get no problem. However I receive a deprecation warning that asked me to use the new parser.
So, when I run it on web browser after those changes, the error message is the following:
VM188:1932 Uncaught
AssertionError {name: "AssertionError", actual: null, expected: TypeError: qs.unescape is not a function
at parseConnectionString (<anonymous>:52229:75)
at …, operator: "==", message: "null == [TypeError: qs.unescape is not a function]", …}
actual: null
expected: TypeError: qs.unescape is not a function at parseConnectionString (<anonymous>:52229:75) at connect (<anonymous>:68112:3) at connectOp (<anonymous>:68216:3) at executeOperation (<anonymous>:71488:24) at MongoClient.connect (<anonymous>:64885:10) at Object.274.assert (<anonymous>:73718:8) at o (<anonymous>:1:265) at r (<anonymous>:1:431) at <anonymous>:1:460 at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)
generatedMessage: true
message: "null == [TypeError: qs.unescape is not a function]"
name: "AssertionError"
operator: "=="
stack: "AssertionError: null == [TypeError: qs.unescape is not a function]↵ at <anonymous>:73719:10↵ at err (<anonymous>:71483:14)↵ at executeCallback (<anonymous>:71472:25)↵ at executeOperation (<anonymous>:71490:7)↵ at MongoClient.connect (<anonymous>:64885:10)↵ at Object.274.assert (<anonymous>:73718:8)↵ at o (<anonymous>:1:265)↵ at r (<anonymous>:1:431)↵ at <anonymous>:1:460↵ at m (http://localhost/mudfeval-mobile/public/src/js/jquery-3.3.1.min.js:2:711)"
__proto__: Error
Is it because of browserify?
javascript node.js mongodb
javascript node.js mongodb
edited Nov 8 at 12:14
asked Nov 8 at 9:10
Ciconia Grullera
33
33
This could be because you create a new connection every time when you need it. If this is the case, the problem isn't with the code what you pasted (it seems fine to me), but the number of the times when you import it from your routes for example. The solution would be to initiate one connection only and share it across the whole server.
– lependu
Nov 8 at 9:18
It cannot be the case because sometimes I have created PHP applications that call different times the correspondant functions to connect to the server sucessfully, @lependu.
– Ciconia Grullera
Nov 8 at 9:27
What node version are you using? Are you seeing Connected successfully to server being logged or do you get the error on first connect try?
– n32303
Nov 8 at 10:29
According to npm, 3.10.10 version, @n32303. On the other hand I get the error on first connect attempt.
– Ciconia Grullera
Nov 8 at 10:32
That's probably npm version. Can you try executing 'node -v' ?
– n32303
Nov 8 at 10:33
|
show 11 more comments
This could be because you create a new connection every time when you need it. If this is the case, the problem isn't with the code what you pasted (it seems fine to me), but the number of the times when you import it from your routes for example. The solution would be to initiate one connection only and share it across the whole server.
– lependu
Nov 8 at 9:18
It cannot be the case because sometimes I have created PHP applications that call different times the correspondant functions to connect to the server sucessfully, @lependu.
– Ciconia Grullera
Nov 8 at 9:27
What node version are you using? Are you seeing Connected successfully to server being logged or do you get the error on first connect try?
– n32303
Nov 8 at 10:29
According to npm, 3.10.10 version, @n32303. On the other hand I get the error on first connect attempt.
– Ciconia Grullera
Nov 8 at 10:32
That's probably npm version. Can you try executing 'node -v' ?
– n32303
Nov 8 at 10:33
This could be because you create a new connection every time when you need it. If this is the case, the problem isn't with the code what you pasted (it seems fine to me), but the number of the times when you import it from your routes for example. The solution would be to initiate one connection only and share it across the whole server.
– lependu
Nov 8 at 9:18
This could be because you create a new connection every time when you need it. If this is the case, the problem isn't with the code what you pasted (it seems fine to me), but the number of the times when you import it from your routes for example. The solution would be to initiate one connection only and share it across the whole server.
– lependu
Nov 8 at 9:18
It cannot be the case because sometimes I have created PHP applications that call different times the correspondant functions to connect to the server sucessfully, @lependu.
– Ciconia Grullera
Nov 8 at 9:27
It cannot be the case because sometimes I have created PHP applications that call different times the correspondant functions to connect to the server sucessfully, @lependu.
– Ciconia Grullera
Nov 8 at 9:27
What node version are you using? Are you seeing Connected successfully to server being logged or do you get the error on first connect try?
– n32303
Nov 8 at 10:29
What node version are you using? Are you seeing Connected successfully to server being logged or do you get the error on first connect try?
– n32303
Nov 8 at 10:29
According to npm, 3.10.10 version, @n32303. On the other hand I get the error on first connect attempt.
– Ciconia Grullera
Nov 8 at 10:32
According to npm, 3.10.10 version, @n32303. On the other hand I get the error on first connect attempt.
– Ciconia Grullera
Nov 8 at 10:32
That's probably npm version. Can you try executing 'node -v' ?
– n32303
Nov 8 at 10:33
That's probably npm version. Can you try executing 'node -v' ?
– n32303
Nov 8 at 10:33
|
show 11 more comments
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
From your update I get that you try to connect directly to a MongoDB via web browser by using Browserify.
I do not think that this will work. A connection to MongoDB is done by a TCP connection, which will not be available from your browser, or to be more precise: I highly doubt that is that simple as using Browserify
and everything is OK. There is probably no driver to connect to MongoDB in your browser or many other prerequisites which certainly are not all in my mind.
See this for a suitable answer: Connecting to mongodb through the browser?
Got it. I understand I cannot invoke it through web browser. Thanks.
– Ciconia Grullera
Nov 8 at 15:33
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
From your update I get that you try to connect directly to a MongoDB via web browser by using Browserify.
I do not think that this will work. A connection to MongoDB is done by a TCP connection, which will not be available from your browser, or to be more precise: I highly doubt that is that simple as using Browserify
and everything is OK. There is probably no driver to connect to MongoDB in your browser or many other prerequisites which certainly are not all in my mind.
See this for a suitable answer: Connecting to mongodb through the browser?
Got it. I understand I cannot invoke it through web browser. Thanks.
– Ciconia Grullera
Nov 8 at 15:33
add a comment |
up vote
0
down vote
accepted
From your update I get that you try to connect directly to a MongoDB via web browser by using Browserify.
I do not think that this will work. A connection to MongoDB is done by a TCP connection, which will not be available from your browser, or to be more precise: I highly doubt that is that simple as using Browserify
and everything is OK. There is probably no driver to connect to MongoDB in your browser or many other prerequisites which certainly are not all in my mind.
See this for a suitable answer: Connecting to mongodb through the browser?
Got it. I understand I cannot invoke it through web browser. Thanks.
– Ciconia Grullera
Nov 8 at 15:33
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
From your update I get that you try to connect directly to a MongoDB via web browser by using Browserify.
I do not think that this will work. A connection to MongoDB is done by a TCP connection, which will not be available from your browser, or to be more precise: I highly doubt that is that simple as using Browserify
and everything is OK. There is probably no driver to connect to MongoDB in your browser or many other prerequisites which certainly are not all in my mind.
See this for a suitable answer: Connecting to mongodb through the browser?
From your update I get that you try to connect directly to a MongoDB via web browser by using Browserify.
I do not think that this will work. A connection to MongoDB is done by a TCP connection, which will not be available from your browser, or to be more precise: I highly doubt that is that simple as using Browserify
and everything is OK. There is probably no driver to connect to MongoDB in your browser or many other prerequisites which certainly are not all in my mind.
See this for a suitable answer: Connecting to mongodb through the browser?
answered Nov 8 at 12:36
Enak
1039
1039
Got it. I understand I cannot invoke it through web browser. Thanks.
– Ciconia Grullera
Nov 8 at 15:33
add a comment |
Got it. I understand I cannot invoke it through web browser. Thanks.
– Ciconia Grullera
Nov 8 at 15:33
Got it. I understand I cannot invoke it through web browser. Thanks.
– Ciconia Grullera
Nov 8 at 15:33
Got it. I understand I cannot invoke it through web browser. Thanks.
– Ciconia Grullera
Nov 8 at 15:33
add a comment |
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%2f53204550%2fcannot-connect-to-mongodb-from-node-js%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
This could be because you create a new connection every time when you need it. If this is the case, the problem isn't with the code what you pasted (it seems fine to me), but the number of the times when you import it from your routes for example. The solution would be to initiate one connection only and share it across the whole server.
– lependu
Nov 8 at 9:18
It cannot be the case because sometimes I have created PHP applications that call different times the correspondant functions to connect to the server sucessfully, @lependu.
– Ciconia Grullera
Nov 8 at 9:27
What node version are you using? Are you seeing Connected successfully to server being logged or do you get the error on first connect try?
– n32303
Nov 8 at 10:29
According to npm, 3.10.10 version, @n32303. On the other hand I get the error on first connect attempt.
– Ciconia Grullera
Nov 8 at 10:32
That's probably npm version. Can you try executing 'node -v' ?
– n32303
Nov 8 at 10:33