MongoDB - DBRefs vs Map/Reduce vs Manual References

MongoDB——dbref vs Map / Reduce vs手册引用

问题 (Question)

I'm pretty new to MongoDB and the NoSQL movement, so bare with me. So far I've come across three different ways of "joining" collections:

  1. Manually keep a "foreign-key-esk" reference to the collection you wish to join with your target collection
  2. Use DBRefs
  3. Write a series of Map/Reduce functions to maintain the relationship

Can someone explain the benefits of and when I should each one?

My first impression is that Map/Reduce is for large, frequently used sets and the other two are mainly meant for small/fast queries.

我很新的MongoDB和NoSQL运动,所以与我裸露的。到目前为止,我遇到的三种不同的方式“加入收藏”:

  1. 手动保持“foreign-key-esk”指收集你想加入你的目标集合
  2. 使用dbref
  3. 写一个系列的Map / Reduce函数来维持关系

有人能解释的好处,当我应该每一个?

我的第一印象是,Map / Reduce是大,常用集和其他两个主要是针对小型/快速查询。

最佳答案 (Best Answer)

Sorry for the late response - here is a simple example of embedded document written in mongoose:

var postSchema = new Schema({
  author : {type : String}, 
  title : {type : String, require : true},
  content : {type : String, require : true},
  comment : {
    owner : {type : String},
    subject : {type: String, require},
    content : {type String, require}
  }
});  

The document here is the postSchema (well it is the schema but I guess you know what I mean).
The comment is the embedded document which you can see it is an object defined inside post.
The benefit is that you get the comment each time you call post without additional query however if you have many comments it makes the post document very large!

抱歉迟到的响应——这是猫鼬嵌入式文档编写的一个简单的例子:

var postSchema = new Schema({

本文翻译自StackoverFlow,英语好的童鞋可直接参考原文:http://stackoverflow.com/questions/16925981