Skip to content
engineering workbench.by StudyPort Academy
Learning path
Advanced16 min

Documents and collections

Understand the idea

A collection holds documents. A document is one JSON-shaped record, not a row in a fixed table.

The idea

MongoDB stores documents in collections. You insert an object. A later matches fields. This Run starts a new in-memory database, loads the insert you see in the file, prints the find, and deletes the database when the process exits.

What changes

Table and collection
SQL habitMongoDB nameWhat is flexible
TableCollectionThe name of the group
RowDocumentWhich fields this record has
Column typeThe value on that documentThe next document can omit a field

Aggregation pipelines can reshape many documents in one query. That is a later pass, not this one.

The command

Insert and find one book

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

The mistake

Check the result

The line is Node notes 12. Run it twice. The second run still prints one book, not two, because the memory server from the first run is already gone.

Guided challenge

Find the Node notes document

The script inserts and finds Other book. Change both the insert and the find so they use the title Node notes.

Find the Node notes document

3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

EXPECTED RESULT

Node notes 12

Hints 0/2

    Use all hints or make 3 failed checks (0/3).

    Free exploration

    Change this example and run it again. Each run is a new process. Nothing is saved.

    Your variation

    3s timeout · one stateless run. Node and Express use Piston when that instance accepts the job (public EMKC execute is whitelist-only; set PISTON_URL or PISTON_TOKEN). Otherwise a local Node process. MongoDB uses a fresh in-memory server per run, then it is stopped.

    Quiz

    A quick check for understanding. Retry as often as you like; your learning path stays open.

    01What is a document?
    02What is a collection?

    Ready to call this one understood?

    Mark this lesson complete to earn 200 XP. You can always revisit it.

    Sign in to save progress
    Next lesson