これが私の状況です:
次のスキーマを持つ Mongo データベースがあります。
var SurveySchema = new Schema({
start_date: Date,
end_date: Date,
title: String,
questions: [ObjectId] //this I want to refer to questions
});
var QuestionSchema = new Schema({
question_text: String,
type: String,
....... (Lots and lots of fields)
});
完全なスキーマ ファイル: https://github.com/nycitt/node-survey-builder-api-server/blob/master/schemas.js
バックボーン モデル: https://github.com/nycitt/node-survey-builder/blob/master/app/js/survey-builder/models.jsおよびコレクションhttps://github.com/nycitt/node-survey-ビルダー/ブロブ/マスター/アプリ/js/調査ビルダー/collections.js
質問は単独で使用できる必要があります (2 ~ 3 の調査に参加すると回答)。しかし、調査は質問を参照する必要があります。
私の理想的な流れは次のとおりです。
- バックボーン呼び出し: GET /api/survey/123 を呼び出し、Mongoose がオブジェクト ID を実際のオブジェクトに変換する (結合を行う) 調査オブジェクトを取得します。
- バックボーン呼び出し: POST /api/survey/123 質問の ID のみを投稿します (これを行うためのバックボーン リレーショナル マジックはありますか)