[DOCS-11175] Document how to project (aggregation) day/month/year from an ISODate field using the Java driver Created: 08/Jan/18  Updated: 27/Jan/21  Resolved: 27/Jan/21

Status: Closed
Project: Documentation
Component/s: drivers
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Angela Morgan (Inactive) Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Participants:
Days since reply: 3 years, 2 weeks, 1 day ago

 Description   

Please document how to project day/month/year from an ISODate field using the Java driver. The customer attached to this docs ticket had difficulty figuring out how to do this and so did I

For example:

Document project = Document.parse("{$project: {year: {$dateToString: {format: '%Y', date: '$Events.eventTime'}}}}");

Thanks,
Angela.



 Comments   
Comment by Nathan Leniz [ 27/Jan/21 ]

Closing this issue as duplicate, a section on common expressions will be included when covering Aggregates builders in the new driver docs

Comment by Angela Morgan (Inactive) [ 09/Jan/18 ]

Created a list of commonly used aggregation pipeline operators here DOCSP-1607. Also, if we go with Shannons tab suggestion, maybe consider an additional tab containing the SQL equivalent (if one exists).

Comment by Angela Morgan (Inactive) [ 09/Jan/18 ]

shannon.bradshaw, Yes, I believe that is correct. The customer tried the following syntax to begin with:

Document dateToString = new Document("format","%Y-%m-%d").append("date", "$EventTime");
Document project = new Document("$project", new Document("dateString",new BasicDBObject("$year","$EventTime")));

then they opened a support ticket when it didn't work.

ricardo.lorenzo pointed me to this link https://groups.google.com/forum/#!msg/mongodb-user/AqZrp1ZhQMY/X3xxkOU0EAAJ with an example of how to use Document.parse() to create a projection object. It helped me create a working example for the customer:

Document project = Document.parse("{$project: {year: {$dateToString: {format: '%Y', date: '$Events.eventTime'}}}}");

I think the tab layout you are suggesting will be convenient and easy to use. My only concern is the customer might not associate the Server>Reference>Operators>Aggregation Pipeline Operators doc with driver examples and fail to find what they are looking for. But if the search works then it probably won't be a problem.

I spoke with jeff.yemin and Kay Kim about this yesterday afternoon on the Java slack channel. Kay said they are planning on providing centralized driver examples in the manual for aggregation, index creation, and running commands. The specific agg examples, they haven't settled on. The timing of this will be sooner rather than later – but will have a more concrete idea of the timing once he returns from vacation.

I'm going to open a DOCSP ticket with commonly used aggregation pipeline operators. I'm thinking about getting some input from John Page with the consulting team as well.

Comment by Shannon Bradshaw (Inactive) [ 08/Jan/18 ]

angela.morgan, from MMSSUPPORT-18282 it looks like the customer's point of confusion was not knowing how to create an object representing the projection they wanted to do using the Java driver (e.g., use Document.parse()). Is that your interpretation?

If so, do you believe it would address the concern if on reference pages such as:
https://docs.mongodb.com/manual/reference/operator/aggregation/dateToString/index.html
there was a Java tab illustrating the way to use a given operator in Java (and Python, JavaScript, etc.)? I am imagining doing something similar to what we do for the CRUD pages in the manual. E.g.,
https://docs.mongodb.com/manual/tutorial/query-documents/

cc: jeff.yemin

Generated at Thu Feb 08 08:02:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.