One-to-one

Coming from the relational DB world, we identify objects by their relationships. A one-to-one relationship could be a person with an address. Modeling it in a relational database would most probably require two tables: a person and an address table with a foreign key person_id in the address table.

The perfect analogy in MongoDB would be two collections, person and address, looking like this:

> db.Person.findOne(){"_id" : ObjectId("590a530e3e37d79acac26a41"), "name" : "alex"}> db.Address.findOne(){"_id" : ObjectId("590a537f3e37d79acac26a42"),"person_id" : ObjectId("590a530e3e37d79acac26a41"),"address" : "N29DD"}

Now we can use the ...

Get Mastering MongoDB 3.x now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.