最終更新: a few seconds ago Remove Netlify-related code from main (grafted, HEAD)
マイリスト機能
特定の
手法
1 コレクション案 (users)
users 内にマイリストに関わる全てのデータを突っ込む
- 👍: コード自体はシンプルになり MongoDB の find 一発で書ける
- 👎: users のスキーマ変更が要る
- 👎: データ数上限
- 👎: ユーザ情報を取得する度に大量のデータ転送が起こらないよう各所で調整が要る
// collection.users
[
{
userEmai: 'alice@example.com',
myLists: [
{
listId: 'mylistId001',
name: '見逃し',
items: [
{ type: 'case', id: 'caseId001', createdAt: '20200101T000000Z' },
{ type: 'case', id: 'caseId002', createdAt: '20200102T000000Z' }
]
},
{
listId: 'mylistId002',
name: 'お気に入り',
items: [
{ type: 'case', id: 'caseId003', createdAt: '20200103T000000Z' }
]
}
]
}
];
2 コレクション案 (users, myLists)
- 👍: users テーブルを触らなくて良い
- 👍: 検索自体は index が効く
- 👎: 1 ドキュメント内に置けるデータ数上限
// collection.mylists
[
{
listId: 'mylistId001',
userId: 'alice@example.com',
name: '見逃し',
items: [
{ type: 'case', id: 'caseId001', createdAt: '20200101T000000Z' },
{ type: 'case', id: 'caseId002', createdAt: '20200102T000000Z' }
]
},
{
listId: 'mylistId002',
userId: 'alice@example.com',
name: 'お気に入り',
items: [{ type: 'case', id: 'caseId003', createdAt: '20200103T000000Z' }]
}
];
3 コレクション案 (users, myLists, myListItems)
- 👍: users テーブルを触らなくて良い
- 👎: 3 コレクションあるのでコードが分かりづらくなりそう
- 👎: 検索は aggregation framework を使う必要がある
users にはマイリストに関わるデータは何も入れず、myLists と myListItems
// collection.mylists
[
{
listId: 'mylistId001',
userId: 'alice@example.com',
name: '見逃し',
count: 2
},
{
listId: 'mylistId002',
userId: 'alice@example.com',
name: 'お気に入り',
count: 1
}
];
// collection.mylistItems
[
{
itemId: 'itemAAA',
listId: 'mylistId001',
type: 'case',
craeteadAt: '20200101T000000Z'
},
{
itemId: 'itemBBB',
listId: 'mylistId001',
type: 'case',
craeteadAt: '20200102T000000Z'
},
{
itemId: 'itemCCC',
listId: 'mylistId002',
type: 'case',
craeteadAt: '20200103T000000Z'
}
];