File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -1455,7 +1455,18 @@ db.collection.<update method>(
1455
1455
<b><a href="#">↥ back to top</a></b>
1456
1456
</div>
1457
1457
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
+
1459
1470
#### Q. ***How to find document with array that contains a specific value?***
1460
1471
#### Q. ***How to find MongoDB records where array field is not empty?***
1461
1472
#### Q. ***How to get the last N records from find?***
You can’t perform that action at this time.
0 commit comments