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

Support fields within DBRef



    • Improvement
    • Status: Closed
    • Minor - P4
    • Resolution: Gone away
    • None
    • None
    • Querying, Usability
    • Minor Change


      This is a proposal for adding additional functionality support to the existing DBRef construct, allowing for fields to be defined within the DBRef that are applied to the referenced document when retrieved by the relevant driver.

      To prevent potential conflicts of key names on the referenced document, DBRef fields should be applied to the document under the '$fields' field.

      A fairly common use case (at least for us) is the requirement of implementing metadata about a relationship between documents, where embedding the document is not an option.

      Our current workaround is to embed a document containing this field metadata along with the DBRef, rather than just embedding the DBRef directly.

      To summarize, recommend adding support for a '$fields' field within a DBRef that can be utilized by a driver to append additional fields to the referenced document when retrieved.

      This would be (I believe) primarily up to the drivers to implement, but would require acceptance by the server team as a standard for database references (http://docs.mongodb.org/master/reference/database-references) so the drivers could support.

      Example document:

          "_id" : ObjectId("52fa898720bdb8b62d2cb99a"),
          "createdBy" : {
              "$ref" : "User",
              "$id" : ObjectId("52d71fa320bdb838565f5f62"),
              "$db" : "users",
              "$fields" : [
                  "type" : "author",
                  "modified" : ISODate("2007-08-20T16:13:53.000Z"),
                  "key" : "value"

      which could result in the following document when parsed by the driver:

          "_id" : ObjectId("52fa898720bdb8b62d2cb99a"),
          "createdBy" : {
              "_id" : ObjectId("52d71fa320bdb838565f5f62"),
              "username" : "testuser",
              "modified": ISODate("2012-12-04T22:20:20.000Z"),
              "$fields": [
                  "type": "author",
                  "modified" : ISODate("2007-08-20T16:13:53.000Z"),
                  "key" : "value"


        Issue Links



              Unassigned Unassigned
              solocommand Joshua Worden
              0 Vote for this issue
              5 Start watching this issue