Skip to content

Instantly share code, notes, and snippets.

@caub
Created August 13, 2019 19:55
Show Gist options
  • Save caub/d2e593c7a488ffa441e5916c51909a43 to your computer and use it in GitHub Desktop.
Save caub/d2e593c7a488ffa441e5916c51909a43 to your computer and use it in GitHub Desktop.

Mongo script gotchas

  • no console.log, use print instead
  • no Object.entries, Object.values use Object.keys
  • Map, Set are not spec-compliant, Set values are stringified, Map are not iterable, don't use them
  • for (const foo of [1]) {} is also broken, it needs a let/var instead of const (warning: let might not be block-scoped as per spec, they probably just replace it by var)
  • Use doc._id + '' to get the objectId as hex string, don't rely on template strings also, they seem to incorrectly invoke doc._id.toString() which returns 'ObjectId(hexstring)'
  • Outdated RegExp, not supporting look-behinds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment