How does MongoDB escape characters in query criteria when using regular queries?

  mongodb, question
keyword = ''
post = collection.find({ 'key': '/^' + keyword })

As shown in the above code, when keyword contains some regular symbols, such as$Such as, the query results are not accurate.
I wonder if mongodb has a built-in escape method, or does it have to escape keyword externally?

Mongodb’s regular expression query has two formats
One is {key:{$regex:”.*”}}
The other is {key:/.*/}
For the first escape use \ \
The second use \