mblarsen / mongoose-hidden

A Mongoose schema plugin for filtering properties you usually do not want to sent client-side like passwords and IDs.
MIT License
89 stars 19 forks source link

undefine is not defined - error with mongoose-hidden #24

Closed naran3434 closed 7 years ago

naran3434 commented 7 years ago

saving data using model, while trying to access the result data i am receiving following error :

ReferenceError: undefine is not defined at getPath (/home/shreeya/Desktop/node/hitchahual/node_modules/mongoose-hidden/lib/mongoose-hidden.js:91:14) at /home/shreeya/Desktop/node/hitchahual/node_modules/mongoose-hidden/lib/mongoose-hidden.js:179:47 at Array.forEach (native) at /home/shreeya/Desktop/node/hitchahual/node_modules/mongoose-hidden/lib/mongoose-hidden.js:172:15 at model.Document.$toObject (/home/shreeya/Desktop/node/hitchahual/node_modules/mongoose/lib/document.js:2130:19) at model.Document.toJSON (/home/shreeya/Desktop/node/hitchahual/node_modules/mongoose/lib/document.js:2348:15) at Object.stringify (native) at stringify (/home/shreeya/Desktop/node/hitchahual/node_modules/express/lib/response.js:1064:12) at ServerResponse.json (/home/shreeya/Desktop/node/hitchahual/node_modules/express/lib/response.js:243:14) at /home/shreeya/Desktop/node/hitchahual/routes/mobile/driver.js:125:20 at /home/shreeya/Desktop/node/hitchahual/node_modules/mongoose/lib/model.js:3408:16 at /home/shreeya/Desktop/node/hitchahual/node_modules/mongoose/lib/document.js:2002:18 at _combinedTickCallback (internal/process/next_tick.js:67:7) at process._tickCallback (internal/process/next_tick.js:98:9)

Any support for this ?

Thanks in Advance.

mblarsen commented 7 years ago

Hi @naran3434 could you post the code that causes this?

I spotted the problem and will fix it now, however I'd like to add this case as a test, so please post your code.

naran3434 commented 7 years ago

Hi @mblarsen kindly look at my code.

--framing array --

array = { first_name : data.first_name, last_name : data.last_name, email : data.email, password : data.password, number : { mobile : data.mobile, country_code : { code : data.country_code, country : data.country_short_code } }, status : 0 };

new DriverModel(array).save(function (err, result) { if (err) return res.send({err: err}); return res.json({status:1, data: result, msg: 'success'}); });

Here when if i try to access result variable or return it. i got the error.

Thanks

mblarsen commented 7 years ago

@naran3434 could you please add your schema as well + where you init the plugin AND please use code blocks to format your code above.

mblarsen commented 7 years ago

@naran3434 note that I did commit a possible fix already, but it has not been published yet. Could you please try it first?

An approach:

  1. Delete node_modules/mongoose-hidden
  2. Clone the repo git clone https://github.com/mblarsen/mongoose-hidden.git node_modules/mongoose-hidden
  3. Run your app again.
naran3434 commented 7 years ago

Sure @mblarsen

naran3434 commented 7 years ago

Thank you @mblarsen. It's working as expected now.

mblarsen commented 7 years ago

Fixed by 79099be

mblarsen commented 7 years ago

@naran3434 0.9.3 published on NPM thanks for the help.

naran3434 commented 7 years ago

@mblarsen Thanks for the quick support.