[SERVER-3089] Ability to make use of a subdocument's data whose contents were used to satisfy a query using the $ operator Created: 13/May/11 Updated: 06/Dec/22 Resolved: 11/Aug/17 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Critical - P2 |
| Reporter: | jp | Assignee: | Backlog - Query Team (Inactive) |
| Resolution: | Duplicate | Votes: | 24 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||
| Assigned Teams: |
Query
|
||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||
| Description |
|
When performing a query against indexed subdocument fields we are able to retrieve and update the subdocument within an array using the $ operator. There are cases where we would have need to know what subdocuments were located who satisfied our query and make use of that data. A simple example would be to locate a document based on its subdocuments content and append a new subdocument that derives from that located subdocument...Given: { "SUBS" : [ { "_id" : 1, "VALUE" : 5 }], "_id" : 1 } Would like to execute something like: db.col.update( { "SUBS._id" : 1 }, { $push : { "SUBS" : { "_id" : 3, "VALUE" : SUBS.$.VALUE * 5 }} } ) That would result in appending a new subdocument "_id":3 in all documents who contain the matched subdocument from our query with a new value derived from the matched subdocument: { "SUBS" : [ , { "_id" : 3, "VALUE" : 25 }], "_id" : 1 } Please see (http://groups.google.com/group/mongodb-user/browse_thread/thread/7f0409356557aa64/468de81a1f938046?lnk=gst&q=serenityexperience#468de81a1f938046) for full discussion. This relates to https://jira.mongodb.org/browse/SERVER-831, but in that case the subdocuments are being updated. This request is for the ability to access the subdocuments content who satisfied the query so we can make further decisions/modifications based on that content. As an added advantage I could seen a lot of power added to JavaScripting if this were also available within JS, for example: function( previousID, newID ) ).forEach( , } } ); In this case, where the primary document was queried based on its subdocument contents, it would be significant if we had access to that data through the passed in matched Document. I am not sure if this would be the ideal syntax but having some way to reference the specific subdocument that satisfied the this outer query can give a lot of power to the inner for making decisions based on such content. |
| Comments |
| Comment by Asya Kamsky [ 15/May/17 ] |
|
I don't think this ticket is asking for anything that |
| Comment by Scott Hernandez (Inactive) [ 14/May/11 ] |
|
I believe the other piece you want will be supported by http://jira.mongodb.org/browse/SERVER-828 |