mongoose.connect(), first argument should be String, received undefined

前端 未结 21 2979
既然无缘
既然无缘 2021-02-12 15:55

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

21条回答
  •  春和景丽
    2021-02-12 16:26

    I came across this same issue and here is my fix: the process.env.MONGODB_URL should be in a string. Check it out

    const mongoose = require('mongoose');
    
    
    mongoose.Promise = global.Promise;
    mongoose.connect('process.env.MONGODB_URI', err => {
        if(err) 
            console.log(err);
        } 
    );
    
    
    
    module.exports = {
        mongoose
    };
    

提交回复
热议问题