-1

Hello I need some help with MongoDB:

My Document has the following property (generated by an Map with spring):

"filter":{"billingAccount_id":["multisim5"],"simulate":["true"]}

and i'm trying to find the document with the this code (generated by spring)

query.addCriteria(Criteria.where("filter").all(getMapWithValues()));

which results in

"filter" : { "$all" : [{ "billingAccount_id" : ["multisim5"] }] }

but i'm getting no result. What's to do here?

Thanks for help in advance

J.Hasler
  • 1
  • 1
  • seeing you data schema, not sure a Map is the best choice. If billingAccount_id and simulate don't need to be array, use custom class for filter field in your @Document annotated java class – matthPen Jul 10 '18 at 17:06
  • The values of filter coming from a Map which are my rest-query parameters (which could contain billingAccount_id = {"multisim5","multisim6"}) – J.Hasler Jul 11 '18 at 08:17

1 Answers1

0

You're applying $all on an object (filter) instead of an array (filter.billingAccount_id). Change your request (and method getMapWithValues) to get something like :

{"filter.billingAccount_id" : { "$all" : ["multisim5"] }}

BUT $all is used to find array that contains, at least, all values provided in query. Since there's an unique element in $all param, $all is useless here, and the following query output the same result :

{"filter.billingAccount_id" : "multisim5"}

EDIT : if you want to query array with exact match ("multisim5" and nothin else), use the following :

{"filter.billingAccount_id" : { "$eq" : ["multisim5"] }}
matthPen
  • 4,253
  • 1
  • 16
  • 16
  • $eq is useless because the map could contain more than one parameter. The example is just the most simple form. But obviously i have to extend my query to check if all arrays are in filter and then check if the arrays contain at least some required values. I'll give it a try. – J.Hasler Jul 11 '18 at 08:21