MongoDB/Spring and @Query

332 views
Skip to first unread message

Sergio Rubio Lafuente

unread,
May 21, 2015, 12:34:30 PM5/21/15
to mongod...@googlegroups.com

I'm working with Spring Boot and MondoDB. My project is growing up, and I'm trying to make complex queries. Working with 'MongoRepository' I tryed to make the following query:

@Query("{$match:{'_id':?0}},{$unwind:'$menuOptions'},{$match:{'menuOptions.active':'true'}},{$unwind:'$menuOptions.menuSubOptions'},{$match:{'menuOptions.menuSubOptions.active':'true'}}")
    Roles findMenu(String name);

With the following result:

Caused by: com.mongodb.MongoException: Can't canonicalize query: BadValue unknown top level operator: $match

I've been trying to make another queries (for instance, a $sort/$orderby with the '@Query' annotation with the same result. Any idea?

Ross Lawley

unread,
May 22, 2015, 6:52:02 AM5/22/15
to mongod...@googlegroups.com

$match is an unknown query operator but is an aggregation pipeline operator, so it looks from the error you are trying to do a find() operation rather than an aggregate() operation.

Ross
Message has been deleted
Message has been deleted

Sergio Rubio Lafuente

unread,
May 25, 2015, 7:31:06 AM5/25/15
to mongod...@googlegroups.com
Thanks! I will try it ! Thing is, why is not working with $orderBy or sort? Find +sort/orderBy should be working, isn't it?

In the other hand, I was trying to find more info about queries + mongoRepository and is hard to find complex compositions, where can i get more info? (Especially MongoRepository+Aggregation)

Thanks a lot!
Reply all
Reply to author
Forward
0 new messages