[SERVER-9272] Querying latest document based on a set of field Created: 08/Apr/13 Updated: 10/Dec/14 Resolved: 29/Apr/13 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Querying |
| Affects Version/s: | 2.4.1 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Minor - P4 |
| Reporter: | Mervin San Andres | Assignee: | J Rassi |
| Resolution: | Duplicate | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||
| Participants: | |||||||||||||
| Description |
|
It would be good if querying can support filtering of recent documents based on certain document fields. For example:
Both documents contain the same case_id. The user can filter out all the most recently uploaded document for each unique combination of fields, for example case_id and group_y. This is helpful in aggregating on a large collection of multiple version of documents. |
| Comments |
| Comment by J Rassi [ 29/Apr/13 ] | |
|
You're suggesting:
For your application, I would suggest one of the following options in the interim:
| |
| Comment by Mervin San Andres [ 25/Apr/13 ] | |
|
Just following up, was my comment clear to you? | |
| Comment by Mervin San Andres [ 16/Apr/13 ] | |
|
Better yet, I am hoping for something like
but with the $max operator implemented as a query operator requiring field parameters. Maybe something like:
which can also be used in a $match pipeline. | |
| Comment by Mervin San Andres [ 11/Apr/13 ] | |
|
Yes, I think you can view it as such. Performance is definitely the issue I am dealing with given the records that I have. | |
| Comment by J Rassi [ 10/Apr/13 ] | |
|
Just checking in – does my above summary accurately reflect your request? | |
| Comment by J Rassi [ 08/Apr/13 ] | |
|
Can you make sure I am understanding you correctly? I will attempt to rephrase your position: The aggregation example given above satisfies your logical requirement for the feature request, however it does not satisfy your performance requirement. Specifically, the example given runs in time O(num docs in collection), assuming there is an index available for the $sort. But, you are interested in a mechanism that runs in time O(unique num docs satisfying constraint). | |
| Comment by Mervin San Andres [ 08/Apr/13 ] | |
|
Actually, the point of the suggested feature is to prevent all the 'redundant' documents to be loaded in the pipeline. Hopefully, the query as passed to the $match pipeline will immediately limit the documents and speed up the grouping. | |
| Comment by J Rassi [ 08/Apr/13 ] | |
|
I believe MongoDB's aggregation framework already supports the feature you're requesting. See the following example query which, for each unique combination of fields a and b, returns the document with the most recent value of t.
Is this what you're looking for? |