Squash Tomato Journal — Oct. 24, 2017–00:24
Published in
1 min readOct 25, 2017
- Redesigned the user register flow.
- Tested the new register flow on a 75year old lady, 2 Gen Xers, 3 Millennials, and 2 Baby Boomers.
- Strongly considered rewriting all pug functionality in Vue — decided to do a future rewrite of the pug functionality (will lighten vanilla JS I had to write)
- Spent 2 hours debugging mongoDB not updating a document with a new item quantity or value. I was using a COMPUTEDKEY to target a specific item’s property (also controlled with a variable) within a user’s list.items (user.list.items). I originally had
const computedKey = `list.items[${itemIndex}].${propertyToChange}`;
. MongoDB doesn’t accept[index]
. Instead, it usesarray.index.property
to target indexes within arrays.
const itemIndex = req.query.index;const newValue = parseFloat(req.query.updatedValue);const propertyToChange = req.query.property;const query = { _id: req.user.id };const computedKey = `list.items.${itemIndex}.${propertyToChange}`;const update = { $set: { [computedKey]: newValue } };const options = { new: true, context: 'query' };const user = await User.findOneAndUpdate(query, update, options);