[SERVER-14563] Filling in with documents with default values after find/aggregate Created: 15/Jul/14  Updated: 14/Mar/17  Resolved: 16/Jul/14

Status: Closed
Project: Core Server
Component/s: Aggregation Framework, Querying
Affects Version/s: 2.7.3
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Allan Cheong Assignee: Ramon Fernandez Marina
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
is documented by DOCS-8998 Filling in with documents with defaul... Closed
Participants:

 Description   

Scenario: I have a collection:

{ "name" : "A", "value" : 1, "date" : ISODate("2014-01-01T00:00:00.000Z") }
{ "name" : "B", "value" : 7, "date" : ISODate("2014-01-01T00:00:00.000Z") }
{ "name" : "A", "value" : 3, "date" : ISODate("2014-01-02T00:00:00.000Z") }
{ "name" : "B", "value" : 8, "date" : ISODate("2014-01-02T00:00:00.000Z") }
{ "name" : "B", "value" : 8, "date" : ISODate("2014-01-03T00:00:00.000Z") }
{ "name" : "A", "value" : 5, "date" : ISODate("2014-01-04T00:00:00.000Z") }
{ "name" : "A", "value" : 4, "date" : ISODate("2014-01-05T00:00:00.000Z") }

The document for A on 3rd Jan 2014 is not available. When I do a find/aggregate on A with a date range from 1/Jul/14 to 31/Jul/14, I would like the document to appear in my result set with a default value (or value same as previous date). For example:

{ "name" : "A", "value" : 1, "date" : ISODate("2014-01-01T00:00:00.000Z") }
{ "name" : "A", "value" : 3, "date" : ISODate("2014-01-02T00:00:00.000Z") }
{ "name" : "A", "value" : 3 (or default value -1), "date" : ISODate("2014-01-03T00:00:00.000Z") }
{ "name" : "A", "value" : 5, "date" : ISODate("2014-01-04T00:00:00.000Z") }
{ "name" : "A", "value" : 4, "date" : ISODate("2014-01-05T00:00:00.000Z") }

URL Reference: http://stackoverflow.com/questions/24752090/filling-in-with-documents-with-default-values-after-find-aggregate



 Comments   
Comment by Allan Cheong [ 17/Jul/14 ]

Noted. Thanks for the answer!

Comment by Asya Kamsky [ 17/Jul/14 ]

I posted an answer on SO with sample code showing how this can be done with aggregation framework.

Comment by Ramon Fernandez Marina [ 16/Jul/14 ]

allancth, the server can't show documents that do not exist, and much less create them on the fly. What you request is very dependent on your application logic, so the best approach is to implement it at the application level in a way that best suits your specific needs.

Regards,
Ramón.

Generated at Thu Feb 08 03:35:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.