MongoDB with Node, SyntaxError: Invalid shorthand property initializer

Issue

i am trying to connect to mongoDB on Node with express

MongoClient.connect(process.env.HOTELS_DB, {useNewUrlParser = false})

I getting the fallowing error

file:///C:/Users/admin/Desktop/fs/mern-stack/index.js:11

MongoClient.connect(process.env.HOTELS_DB, {useNewUrlParser = true})

SyntaxError: Invalid shorthand property initializer

What am i doing wrong here

Solution

You’re using = in the place of : you need to use colon in JavaScript object like key: value https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer

MongoClient.connect(process.env.HOTELS_DB, {useNewUrlParser : false})

Answered By – kiran

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published