ga-wdi-boston / mongoose

An introduction to mongoose
Other
5 stars 136 forks source link

Modify check is probably unnecessary #38

Open raq929 opened 7 years ago

raq929 commented 7 years ago

This is on the solution branch. @payne-chris-r sez:

const update = function(id, field, value) {
  let modify = {};
  modify[field] = value;
  Person.findById(id).then(function(person) {
    person[field] = value;
    return person.save();
  }).then(function(person) {
    console.log(person.toJSON());
  }).catch(console.error).then(done);
};

The o.O is about the two modify lines at the top of the function. It will throw an error if field is undefined. The modify object is not used. If anything, this should be an if(field), but I don't think even that is needed. (Says me.)

gaand commented 7 years ago

I believe this is cruft from using findByIdAndUpdagte.

If modify isn't used, then those two lines should be deleted.