Hello guys, I'm trying to specify that the name field should includes() the passed query criteria for it, can someone help me with the syntax, I can't understand the mongoose documentation.
Example:
Model.find({name: query.search}) -> this way the name property should exactly match the search query. I don't want this.
I want it to make so the name property be toLocaleLowerCase().includes(query.search.toLocaleLowerCase())
#Model.find(query), Mongoose Problem
1 messages · Page 1 of 1 (latest)
Usually, the way this works is you would standardize the data as it goes into the db. That way, you wouldn't need to query based on a lower case version of a string. The string in the db would already be lower cased. Then, then you would lower case the query string as you've already done. Does that make sense?
yeah well, this solves the half of my problem, the other half is that i don't want the query to exactly match the value in the database, i want the includes() side of it
Ah gotcha. Looks like you can pass a regex as referenced here. https://stackoverflow.com/questions/10610131/checking-if-a-field-contains-a-string
It also calls out that this will result in a full table scan as it will look at every record. Definitely would avoid that if possible, but I don't know the way around it for now