0

JavaScript (フレームワークなし) を使用してクライアントのみのアプリケーションを作成し、MongoDB を使用してデータを保存します。データをモデル化する方法は2 つあります。

どちらがより適切かを誰かが理解するのを手伝ってくれませんか。

  • 方法#1

    [{
        title: "bucketList",
        id: 1,
        tasks: [{
            title: "play soccer for world league",
            id: 1,
            done: false,
            comments: ["fifa 2014 is about to start", "need to go buy a Brazil T-shirt"]
        }, {
            title: "start a school",
            id: 2,
            done: true,
            comments: ["start with being a mentor"]
        }]
    }, {
        title: "to-do",
        id: 2,
        tasks: [{
            title: "create a todo App",
            id: 1,
            done: false,
            comments: []
        }, {
            title: "watch GOT",
            id: 2,
            done: false,
            comments: ["whitewalkers seems to be in no hurry"]
        }]
    }]
    
  • 方法 2

    [{
        collection - title: "bucketList",
        collection - id: 1,
        title: "play soccer for world league",
        id: 1,
        done: false,
        comments: ["fifa 2014 is about to start", "need to go buy a Brazil T-shirt"]
    }, {
        collection - title: "bucketList",
        collection - id: 1,
        title: "start a school",
        id: 2,
        done: true,
        comments: ["start with being a mentor"]
    }, {
        collection - title: "to-do",
        collection - id: 2,
        title: "create a todo App",
        id: 1,
        done: false,
        comments: []
    }, {
        collection - title: "to-do",
        collection - id: 2,
        title: "watch GOT",
        id: 2,
        done: false,
        comments: ["whitewalkers seems to be in no hurry"]
    
    }] 
    
4

1 に答える 1

0

私の2つのペニーは次のとおりです。

実際には、データをどのように処理したいかによって異なります。

方法 1 は、多数の do do を含む do do リスト全体を一度に管理します 方法 2 は、それぞれの do do に直接アクセスできます。

方法 1 を使用すると、1 つのリストからすべての To-Do に簡単にアクセスできますが、たとえば「完了」を更新するのは配列であるため、もう少し手間がかかります。

方法#2は「完了」の更新を簡単にしますが、リストのすべてのdo doを見つけるには、反復/集約が必要です。

方法#2は、たとえば完了時の更新は処理が簡単で、複数のドキュメントでの検索は処理が簡単であるため、処理が簡単に思えます。また、データで何をしたいのかを考慮してください。たとえば、期日があり、すべての To Do リストですべての期日タスクを表示したい場合は、方法 #2 が def になります。より良い選択。

于 2014-06-09T09:44:57.200 に答える