I have a collection of books with documents laid out like
{
"title": "The book",
"author": "Joe Bob",
"tags": ["dogs", "funny", "race"],
"categories": ["fiction", "adventure"]
}
I would like to use one search bar to find a book by any of these criteria. I've got this down for the most part, but I don't understand now if it is a search or aggregation I should be using. I also wish I could have everything be case insensitive but I cannot figure out how to do something similar to $options: 'i'
with an $in
operator.
$or : [
{'title': {$regex: search, $options: 'i'}},
{'author': {$regex: search, $options: 'i'}},
{'tags': {$in: [search]}},
{'categories': {$in: [search]}},
]
Is this the best way for me to search through 100s of documents like this? Or should I prefer aggregate.