[SERVER-12695] Support fields within DBRef Created: 12/Feb/14 Updated: 09/Jul/16 Resolved: 13/Aug/15 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying, Usability |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Joshua Worden | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | dbref, reference | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Backwards Compatibility: | Minor Change | ||||||||
| Participants: | |||||||||
| Description |
|
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:
which could result in the following document when parsed by the driver:
|
| Comments |
| Comment by Ramon Fernandez Marina [ 13/Aug/15 ] |
|
Hi solocommand, apologies for the late reply. Given your input above we're going to close this ticket. If the situation changes feel free to post here again (or open a new ticket). Thanks, |
| Comment by Joshua Worden [ 31/Mar/15 ] |
|
jmikola@gmail.com: I'd actually be in favor of just closing out this request. It's been a while and the particular use case is no longer an issue. Also hasn't gotten any votes or feedback in over a year. |
| Comment by Jeremy Mikola [ 08/Mar/15 ] |
|
solocommand: I just came across this ticket. For the record, the server does support additional fields within the DBRef object, although the functionality is undocumented. A concise definition of DBRefs from
Some ODM libraries take advantage of this to keep additional metadata about the reference, such as the class name of the referenced object (based on some discriminator value) or a cached value of some field(s) on the referenced document (which I believe you were doing in your example). I understand this doesn't directly address your request to add $fields to the DBRef specification, but it seemed related and I thought it might be helpful. |