0

Is there any way that i can get a map as a result of a mongodb query using some spring data CrudRepository ? Here is my method which is returning a list of objects.

Query(value = "db.tweet_replies.aggregate([ {$match: { 'in_reply_parent_tweet_ID'  : {$exists : true}}}, {$group: { _id: '$in_reply_parent_tweet_ID', maxDate: {$max : { $cond: [ {$gt : ['authorization_date_time','$user_reply.authorization_date_time']},'$authorization_date_time','$user_reply.authorization_date_time']}}}}])")
List<fReply> findByInReplyParentPostID(final String inReplyParentPostID);

for example it gives me this result.

{ "_id" : "638251888450756608", "maxDate" : NumberLong("1441006865000") }
{ "_id" : "637192023661895680", "maxDate" : NumberLong("1440760528000") }

i want to store this result a typed map instead of object list. Any idea ? . Thanks in advance :)

1 Answer 1

1

It seems there's no simple way to do this, see this question : Can JPA return results as a map?

Maybe you could create a service on top of your CrudRepository in which you translate from the List you have to the Map you wish ?

Sign up to request clarification or add additional context in comments.

1 Comment

that discussion is related to JPA, i have been through that problem before and ended up using the same technique... but this time i am using spring data with CrudRepository interface and problem is related to spring data CrudRepository which is supposed to provide relief from boilerplate code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.