Skip to content

Data Modeling

One-to-One Relationships

When a nested object is enough, and when a second collection is cleaner.

IntermediateAbout 4 minutes

One-to-one is almost always a nested object on the same document. Rahul's address is not a collection. You query "address.city". You update it in the same updateOne as city.

{
  _id: ObjectId("64a1b2c3d4e5f6a7b8c90001"),
  name: "Rahul",
  city: "Bangalore",
  address: { line1: "Indiranagar", city: "Bangalore", pin: "560001" }
}
The default: embed the object

Split into a second collection when the extra object is large and rarely read (a KYC blob, a 2MB settings dump), has a different security boundary, or a different team / service owns it. Then userId on profiles and two reads — or one $lookup on the admin path only. Do not split because SQL had user_profiles.

Interview question

How do you model a one-to-one relationship in MongoDB?

Think about it first.