# How to query documents with "like" statement in Mongoose

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Jul 11, 2022. Topics: Node.js, Mongoose, MongoDB.
Canonical URL: https://attacomsian.com/blog/mongoose-like-regex

> A quick guide to learning how to use the $regex operator to find documents that contain a specific string using Mongoose.

In Mongoose, you can use the `$regex` operator to perform a search query in MongoDB, similar to SQL `LIKE` statement.

MongoDB uses [regular expressions](https://attacomsian.com/blog/javascript-regular-expressions) for pattern matching that is more powerful than SQL `LIKE` statement. Regular expressions allow you to create any search pattern that you can imagine.

Here is an example that [finds documents](https://attacomsian.com/blog/mongoose-find-documents) containing a specific string:

```javascript
const mongoose = require('mongoose')

const User = mongoose.model('User', { name: String })

const users = await User.find({ name: { $regex: /john/i } })
```

Note that the `i` in the above query indicates case in-sensitive match. You can also pass a `RegExp` object instead of `$regex` operator:

```javascript
const users = await User.find({ name: new RegExp('john', 'i') })
```

To match a field that starts with a specific string, you can use the following query:

```javascript
const users = await User.find({ name: { $regex: /^john/i } })
```

Similarly, to find documents that end with a specific string, use the following query:

```javascript
const users = await User.find({ name: { $regex: /john$/i } })
```
