How to get the Count of Two Collections Shares different field with same values

Collection One

    "name" :"latestTest",
    "url" : "

Collection Two

    "name" :"abc",
    "ref" : "thisvalue1"

Here, I have two documents of two different collections of the same DB. I have got the total number of users who have that “ref” value in collection two. It will be different every time when a new user is added to the DB. Have to store them in Array display the total of “url”: " - “ref” : “thisvalue1” these kind of users

is there any Aggregation Query to achieve these kind of functionalities Specially in Spring Boot

Hi @Abishan_Parameswaran ,

In general MongoDB aggregation pipeline can substring or split strings using $split or $substr.

Then you can use $lookup to combine the collections with a proceeding $count.

Did I understand your requirements?


It’s working Thank You @Pavel_Duchovny

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.