Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
Check if MongoDB is connected to MongoDB Atlas

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.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I would say both of your suggestions are considered anti patterns and I would personally avoid both.

What I would personally do is very similar to your first suggestion but instead of checking the value of the connection string I would just use the process.env.NODE_ENV value, this is considered common practice to use this to separate between your dev staging and prod enviorments.


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.

Technically no, as you know atlas search gives you many search engine abilities such as tokenizers and analyzers out of the box. If you have a very specific use case maybe you could engineer a solution to make it work, but that will require you to basically reverse engineer the functionality you're using through atlas which means it's probably not worth the effort.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda