Document Reference
noun
say it: “DOK-yuh-ment REF-er-uns” /ˈdɑkjəmənt ˈrɛfərəns/
A field in one record that holds another record's id, so the two are linked without copying one into the other.
What is a document reference in MongoDB?
A document reference is a field that holds another document's _id, such as customerId in an order, so the two stay linked while each lives in its own collection. Reading both takes a second query or a $lookup.
const ana = db.customers.findOne({ name: "Ana Ruiz" });
db.orders.insertOne({ customerId: ana._id, total: 849.99 });
db.orders.find({ customerId: ana._id }); // all of Ana's orders
In a sentence
- “Each order keeps a document reference to its customer, so a new address is changed in one place.”
- “Following the document reference took a second findOne on customers.”
Level: Apprentice · More MongoDB terms at this level
Updated