These are chat archives for Automattic/mongoose

1st
Mar 2018
Chris Hurst
@ytsruh
Mar 01 2018 11:50
hi all....does anybody have any expereince with text search in mongoose? I have this problem https://stackoverflow.com/questions/49045105/mongoose-text-search-and-casterror
Kev
@lineus
Mar 01 2018 12:20
I don't think find is what you want there @ytsruh. aggregate is probably a better fit. sorry, I don't have time to craft an example, but I'll be back in an hour. docs
the error you're getting there is from the find call trying to convert your input to an id.
Mihajlo Ilijić
@Pritilender
Mar 01 2018 12:23
@ytsruh are you sure that you're getting this error from the Mongoose query provided?
Chris Hurst
@ytsruh
Mar 01 2018 12:25
@lineus cheers. I assumed it was trying to convert to an id, thanks for confirming. I'm honestly lost as to why though. I'll look at aggregate method now but I'm keen on using the find $text method as part of a 'search engine' in my program
@Pritilender 100%. It doesnt make sense to me, becuase I cant understand why its trying to convert to an id
Kev
@lineus
Mar 01 2018 12:26
there might be way to do it, I just never have. I can play around with it after I take my kids to school.
CastError gets thrown by query iirc
Mihajlo Ilijić
@Pritilender
Mar 01 2018 12:27
CastError is thrown because it tries to make ObjectId out of "search" string
You somewhere pass that string literal as something that should be ObjectId
That's why I'm asking for the query, because it doesn't have that nowhere...
Also, note that Mongo has full text search, but not partial text search you'd expect to see from regular search engines.
E.g. if you're looking for user called Pritilender, you won't find that user with Priti only, you'd need to give it Pritilender as a whole to find the user.
Chris Hurst
@ytsruh
Mar 01 2018 12:29
is the query not "soup" in the example I had in StackOverflow?
Mihajlo Ilijić
@Pritilender
Mar 01 2018 12:29
Yes it is, that's why I'm puzzled where is that search string from the error...
Chris Hurst
@ytsruh
Mar 01 2018 12:30
for the moment I've just typed it in.....im hoping to pass it in via req.query later on
Mihajlo Ilijić
@Pritilender
Mar 01 2018 12:30
Also, if you want partial text search, I'd suggest looking into making index on the field you want to search by and then do a regex match with anchored regex, like /^Priti/i
Index as regular Mongo index, not text index.
Chris Hurst
@ytsruh
Mar 01 2018 12:32
cool, i'll try a regular
regular index
Mihajlo Ilijić
@Pritilender
Mar 01 2018 12:33
But in order for that index to be fast if you have like 500k entries, you'd have to make that anchored regex with ^ at the beggining
Chris Hurst
@ytsruh
Mar 01 2018 12:34
thanks, just tried regaular index but that didnt work either
i'll just rebuild it using regex
cheers for the help though
Mihajlo Ilijić
@Pritilender
Mar 01 2018 12:34
Also, if you're planning to use some part of your collections for searching, I'd suggest looking into piping the data to ElasticSearch. There are some libs that you can use for automatic data replications.
Chris Hurst
@ytsruh
Mar 01 2018 12:35
elastic search is a litle out of my depth at the moment :) next project maybe haha
Mihajlo Ilijić
@Pritilender
Mar 01 2018 12:35
If the problem persists with changing that query on that route, then probably you're looking at the wrong route :D
Chris Hurst
@ytsruh
Mar 01 2018 12:36
@Pritilender hahaha, god if i was using the wrong route I'd be embarassed
Mihajlo Ilijić
@Pritilender
Mar 01 2018 12:36
It's a coincidence that I had a similar partial text search problem on a current project, so this is something that I've gathered after a research.
And we'll use this piping approach to ElasticSearch from Mongo.
Chris Hurst
@ytsruh
Mar 01 2018 12:36
@Pritilender cheers,nice to know im not alone with these issues haha - apreciate your time
Mihajlo Ilijić
@Pritilender
Mar 01 2018 12:37
It's cool :)
Glad I could help.
Mattious
@Mattious
Mar 01 2018 14:53
Hi all already thanks for support. I've deployed a new version of our application on azure webapp. I use cosmodb on azure. I've upgraded the mongoose version to 5.X.X ... but it seems not working with cosmodb. any idea??
Kev
@lineus
Mar 01 2018 14:57
what do you mean by not working @Mattious ?
Mattious
@Mattious
Mar 01 2018 14:57
Thanks :)
Kev
@lineus
Mar 01 2018 14:58
are you seeing errors of some kind?
Mattious
@Mattious
Mar 01 2018 14:58
the connection can be etablished. If i rollback to 4.13.9 it works
i've a timeout ... connection could not be etablished
without any code change just change version it works
Kev
@lineus
Mar 01 2018 15:00
the only obvious code change I can think of from 4 to 5 that effects connections is useMongoClient being set to true by default on 5.
do you have useMongoClient: true on your instance of mongoose4?
can you share the part of your code that establishes the connection ? ( be sure to redact any api tokens if you decide to share )
@Mattious ^
unless it's the native driver change between 4 and 5 that is causing issues. as a funny side note, there are no existing issues in mongoose's repo or in mongodb's jira issue tracker mentioning cosmodb.
Kev
@lineus
Mar 01 2018 15:07
this looks like a relevant answer on stackoverflow though
Mattious
@Mattious
Mar 01 2018 15:14
i 've not useMongoClient in the code. So maybe now is to true and doesn't work
i'll test with set to false
Kev
@lineus
Mar 01 2018 15:15
@Mattious you should probably leave it to true, and try changing your connection string as in the stackoverflow answer.
moving the username:password from the uri to an object literal called auth in your mongoose connection options
Mattious
@Mattious
Mar 01 2018 15:22
Okido i'm going to try and let you knwo if it solve issue