Mongodb/express/typescript: mongodb connection error when I am connecting












0















I am getting next error when I am connecting in express to MongoDB:



MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connection 0 to 127.0.0.1:27017 timed out]
at Pool.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibtopologiesserver.js:564:11)
at Pool.emit (events.js:182:13)
at Pool.EventEmitter.emit (domain.js:442:20)
at Connection.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibconnectionpool.js:317:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at Connection.EventEmitter.emit (domain.js:442:20)
at TLSSocket.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibconnectionconnection.js:257:10)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.EventEmitter.emit (domain.js:442:20)
at TLSSocket.Socket._onTimeout (net.js:449:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)


My configuration code to mongo is:



const options = {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
autoIndex: false, // Don't build indexes
reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
reconnectInterval: 500, // Reconnect every 500ms
poolSize: 10, // Maintain up to 10 socket connections
// If not connected, return errors immediately rather than waiting for reconnect
bufferMaxEntries: 0,
ssl: true,
connectTimeoutMS: 20000, // Give up initial connection after 20 seconds
socketTimeoutMS: 90000, // Close sockets after 90 seconds of inactivity
family: 4 // Use IPv4, skip trying IPv6
};


const host: string = 'mongodb://dmr@127.0.0.1:27017/xxx';


my mongoose code is:



mongoose.connect(host, options).then(() =>  {
//var data = mongoose.model(coleccio, dataSchema);
//var data = conn.db.collection(coleccio);

var action = function (err, collection) {
// Locate all the entries using find
collection.find({"cultura": cultura}).toArray(function(err, results) {
let resp = new Resposta;

resp.coleccio = coleccio;
resp.ok = true;

if (err != null) {
throw err;
}
else
{
results = JSON.parse(JSON.stringify(results));

....

resolve(resp);
});
};

mongoose.connection.db.collection(collection, action);
})
.catch((err) => reject(err))


Web Api is going ok then is not the problem.



I can open database using Mongo. I am connecting as anonymouse in my local machine. Do I need a user for that in the database? Or something similar...



DataBase service tells me next error:



Failed to initialize Performance Counters for FTDC: WindowsPdhError: PdhExpandCounterPathW failed with 'El objeto especificado no se encontró en el equipo.' for counter 'MemoryAvailable Bytes'



MONGOD SERVICE ERROR SCREEN IS:



enter image description here



I am not sure if it is the problem.



Can you help me please?










share|improve this question

























  • you need to create a MongoDB user. examples.javacodegeeks.com/software-development/mongodb/…

    – Rajika Imal
    Jan 2 at 5:33


















0















I am getting next error when I am connecting in express to MongoDB:



MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connection 0 to 127.0.0.1:27017 timed out]
at Pool.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibtopologiesserver.js:564:11)
at Pool.emit (events.js:182:13)
at Pool.EventEmitter.emit (domain.js:442:20)
at Connection.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibconnectionpool.js:317:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at Connection.EventEmitter.emit (domain.js:442:20)
at TLSSocket.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibconnectionconnection.js:257:10)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.EventEmitter.emit (domain.js:442:20)
at TLSSocket.Socket._onTimeout (net.js:449:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)


My configuration code to mongo is:



const options = {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
autoIndex: false, // Don't build indexes
reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
reconnectInterval: 500, // Reconnect every 500ms
poolSize: 10, // Maintain up to 10 socket connections
// If not connected, return errors immediately rather than waiting for reconnect
bufferMaxEntries: 0,
ssl: true,
connectTimeoutMS: 20000, // Give up initial connection after 20 seconds
socketTimeoutMS: 90000, // Close sockets after 90 seconds of inactivity
family: 4 // Use IPv4, skip trying IPv6
};


const host: string = 'mongodb://dmr@127.0.0.1:27017/xxx';


my mongoose code is:



mongoose.connect(host, options).then(() =>  {
//var data = mongoose.model(coleccio, dataSchema);
//var data = conn.db.collection(coleccio);

var action = function (err, collection) {
// Locate all the entries using find
collection.find({"cultura": cultura}).toArray(function(err, results) {
let resp = new Resposta;

resp.coleccio = coleccio;
resp.ok = true;

if (err != null) {
throw err;
}
else
{
results = JSON.parse(JSON.stringify(results));

....

resolve(resp);
});
};

mongoose.connection.db.collection(collection, action);
})
.catch((err) => reject(err))


Web Api is going ok then is not the problem.



I can open database using Mongo. I am connecting as anonymouse in my local machine. Do I need a user for that in the database? Or something similar...



DataBase service tells me next error:



Failed to initialize Performance Counters for FTDC: WindowsPdhError: PdhExpandCounterPathW failed with 'El objeto especificado no se encontró en el equipo.' for counter 'MemoryAvailable Bytes'



MONGOD SERVICE ERROR SCREEN IS:



enter image description here



I am not sure if it is the problem.



Can you help me please?










share|improve this question

























  • you need to create a MongoDB user. examples.javacodegeeks.com/software-development/mongodb/…

    – Rajika Imal
    Jan 2 at 5:33
















0












0








0








I am getting next error when I am connecting in express to MongoDB:



MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connection 0 to 127.0.0.1:27017 timed out]
at Pool.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibtopologiesserver.js:564:11)
at Pool.emit (events.js:182:13)
at Pool.EventEmitter.emit (domain.js:442:20)
at Connection.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibconnectionpool.js:317:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at Connection.EventEmitter.emit (domain.js:442:20)
at TLSSocket.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibconnectionconnection.js:257:10)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.EventEmitter.emit (domain.js:442:20)
at TLSSocket.Socket._onTimeout (net.js:449:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)


My configuration code to mongo is:



const options = {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
autoIndex: false, // Don't build indexes
reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
reconnectInterval: 500, // Reconnect every 500ms
poolSize: 10, // Maintain up to 10 socket connections
// If not connected, return errors immediately rather than waiting for reconnect
bufferMaxEntries: 0,
ssl: true,
connectTimeoutMS: 20000, // Give up initial connection after 20 seconds
socketTimeoutMS: 90000, // Close sockets after 90 seconds of inactivity
family: 4 // Use IPv4, skip trying IPv6
};


const host: string = 'mongodb://dmr@127.0.0.1:27017/xxx';


my mongoose code is:



mongoose.connect(host, options).then(() =>  {
//var data = mongoose.model(coleccio, dataSchema);
//var data = conn.db.collection(coleccio);

var action = function (err, collection) {
// Locate all the entries using find
collection.find({"cultura": cultura}).toArray(function(err, results) {
let resp = new Resposta;

resp.coleccio = coleccio;
resp.ok = true;

if (err != null) {
throw err;
}
else
{
results = JSON.parse(JSON.stringify(results));

....

resolve(resp);
});
};

mongoose.connection.db.collection(collection, action);
})
.catch((err) => reject(err))


Web Api is going ok then is not the problem.



I can open database using Mongo. I am connecting as anonymouse in my local machine. Do I need a user for that in the database? Or something similar...



DataBase service tells me next error:



Failed to initialize Performance Counters for FTDC: WindowsPdhError: PdhExpandCounterPathW failed with 'El objeto especificado no se encontró en el equipo.' for counter 'MemoryAvailable Bytes'



MONGOD SERVICE ERROR SCREEN IS:



enter image description here



I am not sure if it is the problem.



Can you help me please?










share|improve this question
















I am getting next error when I am connecting in express to MongoDB:



MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connection 0 to 127.0.0.1:27017 timed out]
at Pool.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibtopologiesserver.js:564:11)
at Pool.emit (events.js:182:13)
at Pool.EventEmitter.emit (domain.js:442:20)
at Connection.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibconnectionpool.js:317:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at Connection.EventEmitter.emit (domain.js:442:20)
at TLSSocket.<anonymous> (C:UsersXXXsourcereposCV_Developmentcv_backendnodejsback-newnode_modulesmongodb-corelibconnectionconnection.js:257:10)
at Object.onceWrapper (events.js:273:13)
at TLSSocket.emit (events.js:182:13)
at TLSSocket.EventEmitter.emit (domain.js:442:20)
at TLSSocket.Socket._onTimeout (net.js:449:8)
at ontimeout (timers.js:436:11)
at tryOnTimeout (timers.js:300:5)
at listOnTimeout (timers.js:263:5)
at Timer.processTimers (timers.js:223:10)


My configuration code to mongo is:



const options = {
useNewUrlParser: true,
useCreateIndex: true,
useFindAndModify: false,
autoIndex: false, // Don't build indexes
reconnectTries: Number.MAX_VALUE, // Never stop trying to reconnect
reconnectInterval: 500, // Reconnect every 500ms
poolSize: 10, // Maintain up to 10 socket connections
// If not connected, return errors immediately rather than waiting for reconnect
bufferMaxEntries: 0,
ssl: true,
connectTimeoutMS: 20000, // Give up initial connection after 20 seconds
socketTimeoutMS: 90000, // Close sockets after 90 seconds of inactivity
family: 4 // Use IPv4, skip trying IPv6
};


const host: string = 'mongodb://dmr@127.0.0.1:27017/xxx';


my mongoose code is:



mongoose.connect(host, options).then(() =>  {
//var data = mongoose.model(coleccio, dataSchema);
//var data = conn.db.collection(coleccio);

var action = function (err, collection) {
// Locate all the entries using find
collection.find({"cultura": cultura}).toArray(function(err, results) {
let resp = new Resposta;

resp.coleccio = coleccio;
resp.ok = true;

if (err != null) {
throw err;
}
else
{
results = JSON.parse(JSON.stringify(results));

....

resolve(resp);
});
};

mongoose.connection.db.collection(collection, action);
})
.catch((err) => reject(err))


Web Api is going ok then is not the problem.



I can open database using Mongo. I am connecting as anonymouse in my local machine. Do I need a user for that in the database? Or something similar...



DataBase service tells me next error:



Failed to initialize Performance Counters for FTDC: WindowsPdhError: PdhExpandCounterPathW failed with 'El objeto especificado no se encontró en el equipo.' for counter 'MemoryAvailable Bytes'



MONGOD SERVICE ERROR SCREEN IS:



enter image description here



I am not sure if it is the problem.



Can you help me please?







mongodb typescript express mongoose






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 2 at 14:43









Nilay Patel

604




604










asked Jan 1 at 20:55









DavidDavid

2,14551737




2,14551737













  • you need to create a MongoDB user. examples.javacodegeeks.com/software-development/mongodb/…

    – Rajika Imal
    Jan 2 at 5:33





















  • you need to create a MongoDB user. examples.javacodegeeks.com/software-development/mongodb/…

    – Rajika Imal
    Jan 2 at 5:33



















you need to create a MongoDB user. examples.javacodegeeks.com/software-development/mongodb/…

– Rajika Imal
Jan 2 at 5:33







you need to create a MongoDB user. examples.javacodegeeks.com/software-development/mongodb/…

– Rajika Imal
Jan 2 at 5:33














0






active

oldest

votes











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998875%2fmongodb-express-typescript-mongodb-connection-error-when-i-am-connecting%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53998875%2fmongodb-express-typescript-mongodb-connection-error-when-i-am-connecting%23new-answer', 'question_page');
}
);

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







Popular posts from this blog

MongoDB - Not Authorized To Execute Command

How to fix TextFormField cause rebuild widget in Flutter

in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith