Skip to content
Advertisement

MongoDB Aggregation Pipeline – Count no of records that are matching a complex criteria – (Couldn’t find PersistentEntity for type java.lang.Object!)

I have documents with dynamic fields and I would need to find a count of matching records for a given complex query criteria

Example Entity

JavaScript

Example Data:

JavaScript

Expected Query Criteria:

JavaScript

Building such complex Criteria using $match would be too much of implementation, so I was trying to use SPEL evolution through $project like below:

JavaScript

However, the above logic failing due to an exception:

JavaScript

I tried digging in further, it seems to fail while its trying to map the fields used within the project to a proper entity object and in this case the projection fields here are actually are of Map object and its unable to identify the matching Entity (of-course the Map is within the UserAttributesEntity) – Is there a better way to solve my problem other than the above approach?

Advertisement

Answer

Using the raw aggregation resolved the issue:

JavaScript
Advertisement