question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for $rand aggregation operator.

See original GitHub issue

This is a first-timers-only issue.

This means we’ve worked to make it more legible to folks who either haven’t contributed to our codebase before or even folks who haven’t contributed to open source before.

If that’s you, we’re interested in helping you take the first step and can answer questions and help you out as you do. Note that we’re especially interested in contributions from people from groups underrepresented in free and open source software!

If you have contributed before, consider leaving this one for someone new, and looking through our general ideal-for-contribution issues. Thanks!

Problem

MongoDB 4.4.2 introduced a new aggregation operator $rand that we want to support via the Aggregation Framework. Details about the operator can be found within the MongoDB Reference Documentation.

Solution

Introduce MathOperators to the org.springframework.data.mongodb.core.aggregation package and add a Rand type that implements AggregationExpression. You may want to have a look at ArithmeticOperators to get an impression what this could look like. Update org.springframework.data.mongodb.core.spel.MethodReferenceNode to add SpEL support for the operator via a rand() method.

Make sure to provide tests that assert the expression can be used within an pipeline and produces the desired command. Again you may want to have a look at existing examples (eg. ArithmeticOperatorsUnitTests & SpelExpressionTransformerUnitTests).

Steps to Fix

  • Claim this issue with a comment below and ask any clarifying questions you need
  • Set up a repository locally following the Contributing Guidelines
  • Try to fix the issue following the steps above
  • Commit your changes and create a pull request

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
christophstroblcommented, Jul 30, 2021

It’s fine to have them there. In case we want to introduce MathOperators at some point we can still delegate.

0reactions
ahmedmqcommented, Jul 28, 2021

@christophstrobl - Any reason why we do not want to have the new rand() aggregation as part of the existing ArithmeticOperators? I was thinking we would mostly use the rand() operator to perform some arithmetic computation as part of the aggregation pipeline.

Read more comments on GitHub >

github_iconTop Results From Across the Web

$rand (aggregation) — MongoDB Manual
New in version 4.4.2. Returns a random float between 0 and 1 each time it is called. ... The $rand operator doesn't take...
Read more >
Aggregation and Grouping | Python Data Science Handbook
Iteration over groups¶. The GroupBy object supports direct iteration over the groups, returning each group as a Series or DataFrame :.
Read more >
Update all documents in a collection with random numbers
I am trying to update all documents in a collection with random numbers. Each document should have a different number. My current code...
Read more >
$out (aggregation)
The $out operator lets the aggregation framework return result sets of any size. Changed in version 3.2.0: MongoDB 3.2 added support for document...
Read more >
Legacy SQL Functions and Operators | BigQuery - Google Cloud
In rows added because of the ROLLUP function, NULL indicates the columns for which the aggregation is rolled up. Example. This query generates...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found