To convert a string to an integer in MongoDB, you can use the $toInt aggregation operator, which is part of the aggregation framework. This operator takes a single argument, typically a field or expression that results in a string, and converts it to an integer. You typically use it within an aggregation pipeline, such as in the $project stage, to modify the documents' fields. If the conversion is not possible, this operator will produce a null value.