I want to have an efficient query witch will give me all products and it’s categories from 500k docs collection.
It should be a search by product title query which return something like this
products: [{},{}],
availableCategories: ["Phones", "Tools"],
total_records_found: 1000
For now I have this query and thinking how to extend it
db.products.aggregate([
{$match: { $text: { $search: "Iphone 11 screen protector" } } },
{$sort: { score: { $meta: "textScore" } }},
{$skip: 0 },
{$limit: 10}
])
I have also text index for product_title and 1 (ask) index for category_name
I am also thinking how to select a particular collection like “Phones” and do search only there if user provides it
Would be grateful for any help!