Using regular expressions for querying MongoDB documents

Ladies and gents, here’s one fairly short hint for anyone wondering how to query documents in mongodb using regular expressions. Let’s get straight to the point:

Let’s start by inserting couple of documents (using mongodb shell) which we’ll use for querying afterwards:

db.developers.insertMany([
    { "name" : "John", "languages" : ["java", "php", "javascript"] },
    { "name" : "Johnny", "languages" : ["java", "c", "c++"] },
    { "name" : "Jim", "languages" : ["node", "java"] }
]);

Continue reading

Advertisements