How do I manage MongoDB connections in a Node.js web application?

前端 未结 11 2480
旧巷少年郎
旧巷少年郎 2020-11-22 02:42

I\'m using the node-mongodb-native driver with MongoDB to write a website.

I have some questions about how to manage connections:

  1. Is it enough using

11条回答
  •  滥情空心
    2020-11-22 03:23

    mongodb.com -> new project -> new cluster -> new collection -> connect -> IP address: 0.0.0.0/0 & db cred -> connect your application -> copy connection string and paste in .env file of your node app and make sure to replace "" with the actual password for the user and also replace "/test" with your db name

    create new file .env

    CONNECTIONSTRING=x --> const client = new MongoClient(CONNECTIONSTRING) 
    PORT=8080 
    JWTSECRET=mysuper456secret123phrase
    

提交回复
热议问题