Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

102
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda