0

I started using mongoose recently. I wondered today for a illogical code writed by my friend that is working without error. That code is in below...

dologin: (logindata) => {

        const { logemail, logpassword } = logindata

        return new Promise(async (resolve, reject) => {
            let user = await usermodel.findOne({ logemail})
            const response = {
                usernotfound: false
            }
.....
....
....

in this the query argument of 'findOne' is an object that is a variable assigned a value by object destructuring without any keyword. it is properly working without any error. The questions are arised in my mind: if it is correct, which field in the collection, that value will cross check with that? and How the selection? is there anything more than normal value asigning in object destructuring, it is value asigning for multiple variables corresponding the order? if it is not correct, then why does it work?

sorry for my bad English. Thank you!

1 Answers1

0

The object literal property value shorthand was introduced in ES6 to make the object initialization shorter.

It allows us to define an object whose keys have the same names as the variables passed-in as properties, by simply passing the variables.

Read official document: