私のDBスキーマはMongoで使用しても大丈夫ですか?
-
09-10-2019 - |
質問
tl; dr私のスキーマは大丈夫ですか?
今年の私の決意は、何か新しいことを学ぶことであり、私は非RELデータベース、すなわちマンゴについて何かを学ぶことを選択しました。現在、Mongoをデータベースエンジンとして使用するシンプルなアプリに取り組んでいます。
私が取り組んでいるアプリケーションは簡単なアンケートアプリです:管理者は質問を作成します(ログイン)ユーザーはそれらに答えます。したがって、ユーザーは多くの答えを質問に属します。 このようなアプリに最も適切なスキーマは何でしょうか? 私は次のスキーマ(擬似)を作成しましたが、これを解決するヒント/ヒントがあるかどうか疑問に思っています。
users [
{
# some required fields to authenticate the user
email: j.doe@example.com,
password: ...
etc.
# next fields are this users answers to a question
# the key is the question's id, it's value the answer
1: 'John',
2: 'Doe',
},
]
questions [
{ # no 1 (I know id's in mongo aren't numbered this way,
# this is just for the sake of readability.
question: What is your first name?,
type: open,
required: true,
},
{ # no 2
question: What is your last name?,
type: open,
required: false,
},
# and so on.
]
解決
私は質問の中で答えを動かしますコレクション:
{_id: 1,
question: "?",
type: "open",
required: true,
answered: [
{email: "j.doe@example.com", answer: "John"},
{email: "bob@example.com", answer: "Bob"},
]
}
また、動的フィールド(回答IDなど)を使用すると、それらをインデックス化することができなくなります。
所属していません StackOverflow