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

109
Visualizações
Query to do indepth search for a regex is not working properly

I'm having one query to do indepth search for a regex in mongoDB. I'm using JS function inside the query like this -

db.collection.find(
        {$where: function() {
        function  deepIterate(obj, value) {
        var new_value = new RegExp("^"+value, "i");
        for (var field in obj) {
            if (obj[field] == new_value){
                return true;
            }
            var found = false;
            if ( typeof obj[field] === 'object' ) {
                found = deepIterate(obj[field], new_value)
                if (found) { return true; }
            }
        }
        return false;
    };
    return deepIterate(this, "[A-Ba-b0-9]*60.51[A-Ba-b0-9]*")
}}
)

It doesn't return any values, output is Fetched 0 record(s) in 4ms. But I'm having one string in my database - 192.108.60.51. That record is not getting returned. Help!!!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can change your regex pattern into deepIterate(this, "(([1-9]?\\d|1\\d\\d|2[0-5][0-5]|2[0-4]\\d)\\.){3}([1-9]?\\d|1\\d\\d|2[0-5][0-5]|2[0-4]\\d)$") this regex is for find string that is an Ip-Address. You can't find any record because your regex pattern not match with your record in database

about 4 years ago · Juan Pablo Isaza Relatório

0

Found out the solution -

db.collection.find({$where: function() {
        function  deepIterate(obj, value) {
        new_value = new RegExp(value, 'i');
        for (var field in obj) {
            if (new_value.test(obj[field])){
                return true;
            }
            var found = false;
            if ( typeof obj[field] === 'object' ) {
                found = deepIterate(obj[field], new_value)
                if (found) { return true; }
            }
        }
        return false;
    };
    return deepIterate(this, "[A-Ba-b0-9]*60.51[A-Ba-b0-9]*")
}})
about 4 years ago · Juan Pablo Isaza 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