#Model.find(query), Mongoose Problem

1 messages · Page 1 of 1 (latest)

thin cipher
#

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())

flint mural
#

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?

thin cipher
#

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

flint mural
#

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

thin cipher
#

is that some kind of helper $contains:{name: query.search}

#

thanks I think that i found it

#

I guess thisi s enought