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

前端 未结 21 2906
既然无缘
既然无缘 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条回答
  •  -上瘾入骨i
    2021-02-12 16:22

    Since error message returned UNDEFINED uri parameter, .toString() will NOT work. You can use the String() function: String(your connection parameter).
    Also, in if(env === 'test' || env === 'development') try not to use (===), it is a strict equality.

    Instead try if(env == 'test' || env == 'development'). This is a loose equality. It doesn't care about the type match and will convert second operand's type to first one's type.

提交回复
热议问题