Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-745

Embedded Document Expansion (Pseudo-JOINs)

    XMLWordPrintable

Details

    • New Feature
    • Status: Closed
    • Major - P3
    • Resolution: Duplicate
    • None
    • None
    • Usability
    • None

    Description

      Taking a bit of inspiration from CouchDB (http://blog.couch.io/post/446015664/whats-new-in-apache-couchdb-0-11-part-two-views) it would be nice for MongoDB to support JOIN-esque operations by using a special "document expander" query command. It is common practice in MongoDB to store partial documents as references, including the DocID and some other attributes useful for displaying that document in the context of the parent document. For instance if I have a document with a "users" key it might contain several users that look like:

      { "_id":DocID("ab2372a4a24"), "name":"User Name", "photo":"http://profile.photo.url"}

      Presumably in these cases the embedded document could be considered a "fragment" of the document referenced in the ID. It would, therefore, be extremely useful to be able to automatically "expand" that fragment into the full document when necessary via the query syntax. Let's say that a "posts" collection has documents with a "users" key containing many fragments as described above. If I perform a query that looks like this:

      db.posts.find().join(

      {"users":"users"}

      )

      Then MongoDB would automatically replace each of the embedded documents in the "users" key with the full document specified in the "users" collection (the document's key being the key in the join argument, the collection being the value). Additionally, passing a "1" value instead would denote that the values contained in the _id field of the given key are DB References that should be dereferenced individually.

      Note that this should work in the following cases:

      • Specified key is an array of strings (assume each string represents a DocID) or DocIDs
      • Specified key is an array of embedded documents, each with an _id field
      • Specified key is a single string (assume string is a DocID) or DocID
      • Specified key is a DBRef
      • Specified key is an array of embedded documents, each with an _id field that contains a DBRef

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mbleigh Michael Bleigh
              Votes:
              18 Vote for this issue
              Watchers:
              17 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: