Sequence NODE_270
Easy

Store Embedded Address in User Document

MongoDB
Technical Specification

Add an embedded address object inside user documents instead of separate collection.

Input/Output Samples
Input:User with address
Output:{ name, email, address: { city, country } }
Optimal Logic Path
db.users.insertOne({
  name: "Happy",
  email: "happy@example.com",
  roles: ["user"],
  address: {
    street: "Some Street",
    city: "Bhubaneswar",
    country: "India",
    pincode: "751001",
  },
  createdAt: new Date(),
});
Architectural Deep-Dive
Embedded docs are great when data is naturally 'belongs to' parent and is read together frequently.