mongodbmapreducedbref

DBRefs vs Map/Reduce vs Manual References


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.


Solution

  • 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!