I have following collections with fields in my mongodb database:
Collection: Category
[
{
"cat_id": "cat_id_1",
"cat_name": "education"
},
{
"cat_id": "cat_id_2",
"cat_name": "Sports"
}
]
Collection: Keywords
[
{
"key_id": "key_id_1",
"key_name": "social"
},
{
"key_id": "key_id_2",
"key_name": "places"
}
]
Collection: Artists
[
{
"art_id": "art_id_1",
"artist_name": "Brian Adams"
},
{
"art_id": "art_id_1",
"artist_name": "ACDC"
}
]
Collection: Episodes
[
{
"ep_id": "ep_id_1",
"ep_title": "Episode Title 1",
"categories": ["cat_id_1", "cat_id_2"],
"keywords": ["key_id_1"],
"program_id": "pr_id_1",
"artists": ["art_id_1", "art_id_2"]
}
]
Collection: Programs
[
{
"program_id": "pr_id_1",
"pr_title": "Program Title 1",
"categories": ["cat_id_1", "cat_id_2"],
"keywords": ["key_id_1"],
"artists": ["art_id_1", "art_id_2"]
}
]
Now I need to write a query which will list programs based on search string matching Category, Artist, keywords, Episodes Title or Program Title. It would have been easy if it's a single collection by just using find
and $regex
and supplying searched string to it. However I failed to apply the same for this condition.