2011-01-11 4 views
0

tl; dr 私のスキーマは大丈夫ですか?私のdbスキーマはMongoでの使用には大丈夫ですか?

今年の私の決断は何か新しいことを学ぶことであり、私はnon-relデータベース、つまりMongoについて学びました。私は現在、mongoをデータベースエンジンとして使用する単純なアプリケーションに取り組んでいます。

私が取り組んでいるアプリケーションは簡単なアンケートアプリです。管理者が質問を作成し、(ログインした)ユーザーが回答します。だから:ユーザーは多くの回答が質問に属しています。 このようなアプリに最も適したスキーマは何でしょうか?私は自分自身(擬似)次のスキーマを作成しましたが、これを解決するヒント/ヒントがあるかどうかは疑問です。

users [ 
    { 
     # some required fields to authenticate the user 
     email: [email protected], 
     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. 
] 

答えて

1

私が質問のコレクション内の回答を動かしたい:

{_id: 1, 
question: "?", 
type: "open", 
required: true, 
answered: [ 
    {email: "[email protected]", answer: "John"}, 
    {email: "[email protected]", answer: "Bob"}, 
] 
} 

も(答えのIDのような)ダイナミックなフィールドを使用してインデックス彼らにあなたが不可能になります。

+1

DBrefのhttp://www.mongodb.org/display/DOCS/Database+Referencesを忘れないでください。 – Falcon

+2

DBRefSはここでは過剰です.MongoDBの主なコンセプトは可能な限りいつも埋め込まれています。http://www.mongodb.org /display/DOCS/Schema+Design#SchemaDesign-Embedvs.Reference – pingw33n

+1

+ '可能な限り埋め込む'。 –

関連する問題