This Week I Learned: 2020-12-06

  1. When it’s used as a pipeline within a $lookup, MongoDB’s $expr operator only supports indexes for equality matches. $in is apparently not considered an equality match, even when the search array only holds one value and in other situations the query parser would treat it as an $eq.
  2. MongoDB supports wildcard indexes to quickly define an index for all fields in a document or subdocument.
  3. Some more useful applications of JavaScript’s Array.reduce() function, beyond summing numbers. I do miss some of the array utility functions from underscore/lodash when I’m working in projects that don’t use them, but it had never occurred to me to try to recreate them like this.
  4. I enjoyed these tips for front-end security and learned a few things (particularly some new HTTP headers such as Content-Security-Policy and X-Frame-Options). I don’t agree that front ends should be sanitising input against SQL injection attacks, though – that is definitely a job for the back end since attackers could bypass the front end altogether and send their malicious content straight to the server, and doing it twice introduces the risk of unwanted double-escaping.
  5. There’s a new media query in town and it’s called prefers-reduced-data. There’s also an HTTP header called Saves-Data, and both are intended to indicate to an application that it should be more conservative with how much data they send to the user. I can see applications for this on the front end (polling the server for updates less frequently, for instance) and the back end (sending fewer fields for each record, or reducing the pagination size), and as a data miser myself I’ll be very interested to see if it achieves widespread support.