I want to do a text search in MongoDB. In development I use a local mongodb, and in production I use MongoDB Atlas. I want to do a $search
Atlas Search if the db I am connected to is MongoDB Atlas. If I'm connected to a local db I want to use $text
.
What I've considered
Check the connection uri
If it ends with .mongodb.net
, use Atlas Search. If not, use normal text search.
Try using $search, then if error use $text
In production it won't be slow because first it will attempt $search
and it will work in production. In development it might be slow because of making an extra failing query every time.
Also
Is there a way of mimicking the Atlas search behavior for a local MongoDB? It's okay if it involves a really slow query but it would be nice to test with same quality text matching as there will be in production.