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 :)

Muhammad Adnan
  • 490
  • 2
  • 12
  • 25

1 Answers1

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 ?

Community
  • 1
  • 1
oailloud
  • 363
  • 1
  • 2
  • 7
  • 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. – Muhammad Adnan Sep 01 '15 at 07:47