そのような場合、データを非正規化する義務はありません。
ユーザーと投稿を別のドキュメントとして (同じデータベースに) 保存できます。
{
"_id":"alice",
"email":"alice@wonderland.org"
}
{
"author":"alice",
"text":"Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, 'and what is the use of a book,' thought Alice 'without pictures or conversation?'"
}
次に、結合に使用されるフィールドを示すマップ関数が必要です。
function(o) {
if (o.text) {
emit(o._id, {text:o.text, _id:o.author});
}
}
include_docs=true次に、投稿の ID を としてこのビューを呼び出しますkey。
このためだけにインデックスを作成するのはやり過ぎかもしれませんが、他の有用な目的 (ブログの投稿やコメントの「照合」など) に再利用できる可能性があります。