MongoDB Courses

Hi everyone!

It has been a long time ago since the last post. I’ve been working an a very interesting course MongoDB for DBA. I will recommend this very interesting and useful course to anyone who wants to understand NoSQL databases, there is a lot of theory in the course, and at the same time it’s very practical, with exercises and a very interesting final exam!

Take a look, and if you have time to involved it, it’s a very good option to improve your knowledge!

And the best of all, it’s free ;D

And once you finished, they send you a certificate, here is mine 😉 Click

MongoDB $regex not working

This will be a quick tip of Mongodb:

I usually try my regular expressions in a Regular Expression “helper” I use gskinner and it’s really nice. My problem appears when here it perfectly works, and not in Mongodb shell.

My regexp:

 \d\w* 

This regular expression match with any word that starts with a decimal [0-9]

What was my mongodb query?

db.zips.find({ "city" : { $regex : "\d\w*" } })

Where was my mistake?

 "\d\w*" 

I thought that the regexp has to be inside “” and it has to be between / /

The solution

 db.zips.find({ "city" : { $regex : /\d\w*/ } }) 

It works perfectly!

This happened to me later in Nginx, I think mongodb and nginx use Perl PCRE.

Useful links

MongoDB $regex doc: $regex
Regular Expression Cheat Sheet
Regular Expression helper: gskinner

Uso de cookies

Este sitio web utiliza cookies para que usted tenga la mejor experiencia de usuario. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información.plugin cookies