Can't connect to my mongodb and backend server
P粉426906369
P粉426906369 2024-02-25 20:27:44
0
1
330

Throw new error_1.MongoAPIError('URI must contain host name, domain name and tld');

Hi everyone, I'm getting an error while connecting my backend to mongodb. I'm a student and I'm learning full stack while developing a project, but I'm getting the above error.

I'm trying to connect my mongodb to my backend server but it won't happen and instead it sends me the error mentioned above.

const connect = async () => {
    try{
        await mongoose.connect('mongodb+srv://rahulghatge166:Rahul@[email protected]/Booking?retryWrites=true&w=majority');
        console.log('Connected to MongoDb')
    }catch(error) {
        throw error
    }
}

mongoose.connection.on('disconnected', () => {
    console.log('mongoDb disconnected')
})
mongoose.connection.on('connected',() => {
    console.log('mongoDb is connected')
})

P粉426906369
P粉426906369

reply all(1)
P粉445750942

Your password has a special character, @. You need to encode it as @.

Change the code to:

const connect = async () => {
try{
    await mongoose.connect('mongodb srv://rahulghatge166:Rahul%[email protected]/Booking?retryWrites=true&w=majority');
    console.log('Connected to MongoDb')
} catch(error) {
    throw error
}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!