- I have a
user collectionwhich has a_idfield. - A user can have a subscription for a api key, hence
userIDis stored insubscription collection - Another collection for
Apiis there which hassubscriptionID
subscription collection:
{
"_id":ObjectId("60924ec559bedd45dd74bd61"),
"userID":ObjectId("6090f048536d345a024b8b60")
}
{
"_id":ObjectId("609141bd392194fde3ba7cf6"),
"userID":ObjectId("6090f048536d345a024b8b60")
}
{
"_id":ObjectId("609141bd392194fde3ba7c54"),
"userID":ObjectId("6090f048536d345a024b8bc2")
}
Api collection:
{
"_id":ObjectId("60924e7426ed2445aab2fc7f"),
"subscriptionID":ObjectId("609143fb036c8a007a5e6a61")
}
{
"_id":ObjectId("60924ec559bedd45dd74bd61"),
"subscriptionID":ObjectId("609141bd392194fde3ba7cf6")
}
{
"_id":ObjectId("60924ec559bedd45dd74bd68"),
"subscriptionID":ObjectId("609141bd392194fde3ba7c54")
}
Now I want to get all the api keys of a user using userID
means I will go through the Api collection find subscriptionID => and then go to the subscription collection and => match the userID with the provided userID
Note- subscriptionID in api collection is unique(a subscription has only one api key) userID is not unique in subscription collection.
input: userID - 6090f048536d345a024b8b60
output: first two api documents