[JAVA-3956] Add a helper method to the fluid API to create a document from other fluid method Created: 22/Jan/21  Updated: 05/Dec/22

Status: Backlog
Project: Java Driver
Component/s: Builders
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Michael Rose (Inactive) Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by COMPASS-4475 Aggregation tool generating Java code... Closed
Quarter: FY23Q4

 Description   

In Compass we are providing the feature to allow users to generate code from the aggregation pipelines they've configured - including Java code.

With the change introduced by JAVA-3338, the code now generates invalid code as we were using and(...) to generate a BSON document.

The code generation takes a BSON document as an input (noted down in valid JavaScript) and transforms it into idiomatic Java using the fluid API. However, the main piece we are lacking from the fluid API now is to create a "flattened" document out of other fluid API calls.

Example input BSON document:

{
    x: "1",
    y: 42
}

Previously generated output:

and( eq("x", "1"), eq("y", 42) )

Which now leads to the (wrong) BSON:

{
   $and: [{ x: "1" }, { y: 42 }]
}

We would love to have a fluid method like doc(...) or flatten(...) that would allow to generate the following Java code:

flatten( eq("x", "1"), eq("y", 42) )

And produces the above mentioned input BSON document as result. The semantics regarding overlapping field properties would be that a later flattened document overrides a previous property.

See COMPASS-4475 and https://mongodb.slack.com/archives/C0V5KNS3X/p1611234779003900 for more context.


Generated at Thu Feb 08 09:00:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.