Skip to content

Commit d74670b

Browse files
committed
Update README.md
1 parent 2b96722 commit d74670b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,18 @@ db.collection.<update method>(
14551455
<b><a href="#">↥ back to top</a></b>
14561456
</div>
14571457
1458-
#### Q. ***How to check if a field contains a substring?***
1458+
## Q. ***How to check if a field contains a substring?***
1459+
1460+
The `$regex` operator can be used to check if a field contains a string in MongoDB.
1461+
1462+
```js
1463+
db.users.findOne({"username" : {$regex : ".*some_string.*"}});
1464+
```
1465+
1466+
<div align="right">
1467+
<b><a href="#">↥ back to top</a></b>
1468+
</div>
1469+
14591470
#### Q. ***How to find document with array that contains a specific value?***
14601471
#### Q. ***How to find MongoDB records where array field is not empty?***
14611472
#### Q. ***How to get the last N records from find?***

0 commit comments

Comments
 (0)