MongoDB can be used for real-time analytics by leveraging its upsert feature and the `$inc` operator, which allows for efficient updates to existing objects without requiring a more expensive query/modify/update sequence. This approach enables developers to track performance metrics in real-time, such as page views and uniques, without relying on traditional tools like Google Analytics. By sending a single message to the server with the update, MongoDB can handle the operation efficiently without waiting for a response, making it suitable for applications that require immediate feedback. The example demonstrates how to use the `mongo` shell syntax to update statistics in real-time using MongoDB's upsert feature and `$inc` operator.