Quiz

  1. Is it okay if we don't have the MongoDB student pack?

    Yes, that's fine.

  2. Why don't the symlink entries in the code in 'Seeing Symlinks' section of the reading have an 's' as the first character?

    D'oh! Because the "s" is an embarrassing typo. You correctly inferred that it's an l for a link.

    I've fixed the reading now; thanks for letting me know.

  3. Can you explain using metacharacters in regular expressions a little more?

    Sure. Usually, regular expressions are about matching strings, but it's more than just string matching. The regex language(s) — there are several, though they are all similar — are about describing patterns.

    Thus, instead of just "anderson" we can match ".*son$" which matches any string ending in "son", like Johnson or Davidson. The metacharacters have meaning:

    • . matches any single character; it's a wildcard
    • * matches zero or more repetitions of the previous pattern, in this case the dot.
    • $ matches the end of the string, so we match "Smithson" but not "Smithsonian"

    Those special characters are called metacharacters.

    They are why regular expressions often look like a cat walked on your keyboard.

  4. How are MongoDB documents/collections/databases stored?

    A database is just a set of related collections.

    A document is JSON, but is actually represented as BSON, which is binary JSON:

    • binary encoded
    • length-prefixed
    • typed (int32, int64, string, date, object, array, etc)
    • designed for fast traversal

    A collection is a sequence of BSON documents.

    The storage engine (WiredTiger) stored data in B+ Trees, which are very cool. (Most SQL databases use B-trees or B+ trees as well.)

    • a tree of nodes, but
    • very large branching factor: hundreds, not two
    • node size determined by disk block size
    • height-balanced: all leaves are at the same level
    • shallow depth: get to any leaf in just a few operations — disk reads
    • Upper level nodes cached in memory.
  5. What makes MongoDB perform better than SQL? Can we compare the two database systems more in depth?

    We will do the comparison, later in the course. It's on the schedule already for April 10th.

  6. In the security implications section: why does {nm: {$eq: userVal}} prevent security breaches when user data is inputted for a query?

    Ah, because the ${eq: userVal} means MongoDB knows that this is an equality test, so even if the uerVal is something like ${gte: 1} (which would match everything and might leak data), that value is just compared to, say, the ID number, and matches nothing instead of everything.