-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to implement $$ROOT #41
Comments
It looks like the easiest way to add the feature is to add the code into the very beginning of the resolve function: if (selector === '$ROOT') {
return obj;
} But it's not generic enough. What do you think? |
From the MongoDB documentation I think it is time to revisit implementing Suggestions and PRs are welcome. |
Thanks for your answer. Let me take a look what the |
I like the way you implemented 'custom operators', so I think the API should be something like this: Mingo.addAggregationVariables(function (m) {
return {
$$ROOT: function(doc , stageRootExpression){
// we can here triverse all the subdocs and array in case of $$DESCEND
// using the stageRootExpression (this should be $cond in case of $reduct)
return doc; // either obj or undefined if we don't want to include the doc into the output
}
}
}) |
I have implemented After careful consideration, I still found the ones available to @zag2art Out of curiousity, what is your use case for requiring |
Looks cool, thanks. I'l take a look more carefully tomorrow. Data set:
Aggregation:
Result:
So, I use |
It seems that
The three are only for On the other hand, the other two ( So, I think, maybe it's better not to include the |
I concur. I found my preliminary implementation to a bit brittle and have removed the |
Cool, thanks. It works like a charm with By the way, I guess the code is wrong a little bit: var sysCurrent = "$$CURRENT";
if (expr.indexOf(sysCurrent + ".") === 0) {
return resolve(obj, expr.slice(sysCurrent.length + 2));
} It slices one extra character from the expression. Also, It seems that I think the |
Just tried it in mongo 3.4. So, this worked fine for me: |
I've added a few tests here - #46 |
Still some more work to do then. My implementation did not handle subpaths for I will make the update in the next minor release. Thanks for the tests. |
How one could implement $$ROOT variable as in here https://docs.mongodb.com/manual/reference/operator/aggregation/group/#group-documents-by-author?
It's in mongo since 2.6.
Do 'custom operators' fit for this?
I tried to implement it this way, but it doesn't work.
It throws the error: "Invalid operator name '$$ROOT'"
The text was updated successfully, but these errors were encountered: