Dino Geek, try to help you

How to perform case insensitive search in MongoDB?


In MongoDB, you can perform a case-insensitive search by using the `$regex` operator along with the `i` option for case-insensitivity.

Here is an example where we are searching for “java” in the “language” field in a case-insensitive manner:

```
db.collection.find({ language: { $regex: /java/i } })
```

In this case, “/java/i” is a regular expression where “java” is what you are searching for and “i” is a flag to specify case-insensitivity.

Or, you can also specify it in a more extended way:

```
db.collection.find({ language: { $regex: /^java$/i } })
```
In this case, “^” means the beginning of a string, and “$” means the end of a string.

If you want to do it in JavaScript:

```
db.collection.find({ language: { $regex: new RegExp(‘^’ + ‘java’ + ‘$’, ‘i’) } })
```
The ‘i’ option can be added to the RegExp constructor in the second parameter to make the search case insensitive.


Simply generate articles to optimize your SEO
Simply generate articles to optimize your SEO





DinoGeek offers simple articles on complex technologies

Would you like to be quoted in this article? It's very simple, contact us at dino@eiki.fr

CSS | NodeJS | DNS | DMARC | MAPI | NNTP | htaccess | PHP | HTTPS | Drupal | WEB3 | LLM | Wordpress | TLD | Domain name | IMAP | TCP | NFT | MariaDB | FTP | Zigbee | NMAP | SNMP | SEO | E-Mail | LXC | HTTP | MangoDB | SFTP | RAG | SSH | HTML | ChatGPT API | OSPF | JavaScript | Docker | OpenVZ | ChatGPT | VPS | ZIMBRA | SPF | UDP | Joomla | IPV6 | BGP | Django | Reactjs | DKIM | VMWare | RSYNC | Python | TFTP | Webdav | FAAS | Apache | IPV4 | LDAP | POP3 | SMTP

| Whispers of love (API) | Déclaration d'Amour |






Legal Notice / General Conditions of Use