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

Collection One

{
    "name" :"latestTest",
    "mobileNumber":"0771234567",
    "description":"test",
    "email":"email@email.com",
    "url" : " www.abcdef.org/thisvalue1
}

Collection Two

{
    "name" :"abc",
    "mobileNumber":"0771234567",
    "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”: " www.abcdef.org/thisvalue1 - “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?

Pavel

It’s working Thank You @Pavel_Duchovny

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