Data Model How to model data relationships between users, posts, and hearts

This lesson is available for PRO members or as a single course purchase. Sign-in and choose a plan below.
Get Unlimited PRO Access

OR


*Enrollment provides full access to this course (and updates) for life.

Database Structure

  • users/{uid} Public user profile
  • usernames/{username} Username uniqueness tracking
  • users/{uid}/posts/{slug} User can have many posts
  • users/{uid}/posts/{slug}/hearts/{uid} many-to-many relationship between users and posts via hearts

Data Model for Posts

Example post document with all expected fields.

// users/{uid}/posts/{slug}

{
    title: 'Hello World,
    slug: 'hello-world',
    uid: 'userID',
    username: 'jeffd23',
    published: false,
    content: '# hello world!',
    createdAt: TimeStamp,
    updatedAt: TimeStamp,
    heartCount: 0,
}

Q&A Chat