$ regex
Provides regular expression capabilities for pattern matching strings in queries. MongoDB uses Perl-compatible regular expressions (ie "PCRE") version 8.36 with UTF-8 support.
$ text
Performs a text search on the contents of fields indexed using a text index .
For data
{ "_id" : 100, "sku" : "abc123", "description" : "Single line description." }
{ "_id" : 101, "sku" : "abc789", "description" : "First line\nSecond line" }
{ "_id" : 102, "sku" : "xyz456", "description" : "Many spaces before line" }
{ "_id" : 103, "sku" : "xyz789", "description" : "Multiple\nline description" }
In the search field sku, which is a single-line value, you can use$regex
db.products.find( { sku: { $regex: /^ABC/i } } )
description, , $text, , description.
db.products.find( { $text: { $search: "coffee" } } )
?
regular expressions , - , "action -superhero" .- , .
.