bradtraversy / microposts_fullstack_vue

Full stack vue and express

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to fetch the database from mlabs

vishal758 opened this issue · comments

After adding the loadPostsCollection() fucntion it is just loading and after a certain time limit it justs "This site cann't be reached".
Can anyone plz look into the issue and tell me how to resolve it.
The loadPostsCollection function is given below:
async function loadPostsCollection() {
const client = await mongodb.MongoClient.connect(
'mongodb://abc123:abc123@ds119343.mlab.com:19343/vue_express',
{
useNewUrlParser: true
}
);

return client.db('vue_express').collection('posts');
}

The error coming is given below:

(node:1092) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [ds119343.mlab.com:19343] on first connect [MongoNetworkError: connect ETIMEDOUT 34.235.146.39:19343] at Pool. (C:\Users\VISHAL-PC\Desktop\vuejs_express\node_modules\mongodb-core\lib\topologies\server.js:564:11)
at Pool.emit (events.js:182:13)
at Connection. (C:\Users\VISHAL-PC\Desktop\vuejs_express\node_modules\mongodb-core\lib\connection\pool.js:317:12)
at Object.onceWrapper (events.js:273:13)
at Connection.emit (events.js:182:13)
at Socket. (C:\Users\VISHAL-PC\Desktop\vuejs_express\node_modules\mongodb-core\lib\connection\connection.js:246:50)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
(node:1092) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated
either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:1092) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Just fork it and use a local mongo instance instead

commented

I used mongodb Atlas and it worked fine.
After signing up at mongodb Atlas, you create a free cluster online and use it as your db.
Your db name is your cluster name that you chose.
When you select your cluster on the mongodb atlas website, click on connect on the right to get the url that you need to paste inside your code.

I used mongodb Atlas and it worked fine.
After signing up at mongodb Atlas, you create a free cluster online and use it as your db.
Your db name is your cluster name that you chose.
When you select your cluster on the mongodb atlas website, click on connect on the right to get the url that you need to paste inside your code.

Did you find MongoDB Atlas quite nice to use? Just wondering as I've never tried it.