java - Spring Data MongoDB: aggregation framework - sort with nested property throws invalid reference -
i found this article in spring forum dicusses partly same problem, has no answer question.
given following document...
{ "_id": { "$oid": "5214b5d529ee12460939e2ba"}, "title": "this title", "tags": [ "fun", "sport" ], "comments": [ { "author": "alex", "text": "this cool", "createdat": 1 }, { "author": "sam", "text": "this bad", "createdat": 2 }, { "author": "jenny", "text": "this bad", "createdat": 3 } ] }
... want aggregation (javascript) ...
//this concise possible focus on actual problem sort operation when ported spring! db.articles.aggregate( {$unwind:"$comments"}, //do more match, group, etc... {$sort:{"comments.createdat":-1}} //sort descending -> here problem occurs in spring (works in javascript!) );
... spring -> throws invalid reference!
aggregation agg = newaggregation( unwind("comments"), sort(direction.desc, "comments.createdat") //throws invalid reference 'comments.createdat'! //how can make work? );
of course can native java-driver , without usage of spring's mongotemplate don't approach much. can make exact aggregation work spring?
i using current version 1.4.0.release.
the code posted indeed works - problem had else.
i did this:
aggregation agg = newaggregation( project("comments"), //this problem! without works desired! unwind("comments"), sort(direction.desc, "comments.createdat") );
as wrote in code wanted project comments-field save overhead - acutally caused problem!
thanks lot hint!
Comments
Post a Comment