i have been working in a Node js small project where i use MongoDB as Database and use mongoose as a Data Modeling Library.
but when i tried to connect to Database its show an which is: Mongoose Error The uri parameter to openUri must be a string-got undefined Make sure the first parameter to mongoose.connect
or mongoose.createConnection is a string
the actual error screen shot is:
after seen this type of error i want to fix why this is happen cause i am 100% confident that there is no any coding issues and i have written well organize code. so i try to find out the problem after few times i got what i did and what is my mistake and then i solve the issue and i decide to share this solution with all of you the internet people.
So, to solve The uri parameter to openUri must be a string-got undefined Make sure the first parameter to mongoose.connect
or mongoose.createConnection is a string
i go to my API index file and place the dbConfig.js file under the dotenv config file. so why dotenv because i have created env file and use dotenv libraray.
and now i want to show 2 screen shot where the first one is hold the Mongoose Error: mongoose.connect or mongoose.createConnection is a string
and the second one is the solution of this type of error i men to say what i exactly did to avoid this type of error.
1 . Screen shot of the code which generate Mongoose connection String error:
2. Screen shot of the code How i solve or avoid Mongoose connection String error:
this all solve my Mongoose Error: Connection String Error. and after solution the terminal scenario is:
.
That's it
Hope this will help you
Happy Coding
.
osman forhad
Full-Stack Developerđź’» (Mobile App & Web App)
developer.osmanforhad@gmail.com
Top comments (0)