首页 > 解决方案 > 您将如何在 DynamoDB 中为一对多和多对多建模

问题描述

您将如何建模以下实体,并在 Node.js 中查询它们?

User --> has many Posts
Post --> each Post belongs to a single User
Image --> each Image belongs to either a User or a Post or an Organization
Organization --> each Organization has many Users,
             --> each User can belong to many Organizations

您是否会在单独的表中创建每个实体并有一个指向所有者实体的字段(a la FK)?您是否会将它们全部存储在一个包含嵌套 json 字段的大型组织表中,并且非规范化数据在不同文档中重复多次?如果是这样 - 您将如何更新属于多个组织的用户字段?

标签: javascriptnode.jsamazon-dynamodb

解决方案


Relational data modeling is very different in NoSQL, compared to SQL (RDBMS), databases. There are a lot a great articles and videos on relational data modeling in DynamoDB. This article is a relatively simple example that you can use to help you get started.

As for the NodeJs part, it's just using the SDK to run the queries as outlined in the article. You'll primarily use the getItem and query functions.


推荐阅读