I am trying to set the test database for the testing purpose, but its not working.
I am trying to connect to mongodb using mongoose, but finding problem in connection er
What I was doing wrong was I created js file to store the key:
module.export = {
MONGOURI : "Your Key"
}
and from my app.js I was fetching the key with different keyname like
const {MongoUri} = require('./keys')
after changing MongoUri to MONGOURI , it worked fine.
const db = process.env.MONGO || 'test'
mongoose.connect(db, {
useNewUrlParser: true,
useUnifiedTopology:true,
useCreateIndex: true
}).then(()=>{
console.log("conected to mongodb");
}).catch(error => {
console.log("mongo error",error);
})
I had the same problem, but then I realized that I saved the .env file as .env.txt which caused the issue. I deleted the file and created another file without .txt at the end and everything worked find.
I hope this helps.
Dhiya Aljaradi