A lot is going right for database software provider MongoDB (MDB 0.81%). Revenue soared 53% year over year in the second quarter, driven by incredible 73% growth for Atlas, MongoDB's fully managed cloud-based database platform. Atlas now accounts for 64% of total revenue, with the rest coming from enterprise-focused products and services.

But that growth came at a cost, and the market is seemingly not thrilled with the price tag. Shares of MongoDB were down nearly 25% early Thursday afternoon despite the company beating analyst estimates and raising its guidance.

Here's the thing: MongoDB isn't profitable. On a GAAP basis, it's not even close. Even adjusted for stock-based compensation, the company is losing money. And all-important free cash flow is in the red as well. MongoDB posted a GAAP net loss of $118.9 million on $303.7 million of revenue in the second quarter, up from a loss of $77.1 million in the prior-year period.

Why can't MongoDB turn a profit?

Let's dig into where MongoDB's revenue actually goes. First, there's the cost of providing its services. Subscription revenue accounts for the vast majority of the company's total revenue, and much of that is coming from Atlas.

A big benefit of selling software is that each additional unit sale costs next to nothing to deliver. For old-school software licenses, once the software has been developed, "making" another copy costs nothing. For software-as-a-service providers, there's likely some costs associated with hosting data. But these costs are usually not very high relative to revenue. Adobe, for example, manages a gross margin of around 88%.

MongoDB's gross margin skews much lower. Gross margin was just 71% in the second quarter, which isn't all that high for a software company. Much of MongoDB's cost of revenue comes from third-party cloud computing. The company doesn't run its own data centers. Instead, each time a customer spins up an Atlas cluster, resources are provisioned on Amazon Web Services or another major cloud provider.

Public cloud computing is not cheap. Powerful virtual servers running in the cloud can get pricey, and bandwidth charges can really add up. The upside of relying on public cloud providers is that scaling Atlas didn't require MongoDB to build out its own data centers. The downside is that costs are almost certainly higher than they would be if the company handled hosting databases itself.

After cost of revenue is subtracted, what's left must cover sales and marketing, research and development, and other operating costs. In MongoDB's case, that gross profit is just not enough. The company has had success winning enterprise customers willing to spend more than $100,000 annually, but that comes with long sales cycles and the need for big sales teams. Sales and marketing spending shot up 67% to $182 million in the second quarter, outpacing revenue growth.

R&D is important for MongoDB because it must keep improving its database product to keep its customers happy and continue to win new customers. There are a ton of options when it comes to database software. MongoDB can't afford to fall behind, and that effort cost the company $108 million in R&D spending in the second quarter.

MongoDB's operating costs totaled $330.2 million in the second quarter. Even if gross margin was 100%, MongoDB would still post a net loss.

Are MongoDB's losses a problem?

The market appears to think that MongoDB's growing losses are not acceptable, at least based on the stock's post-earnings slump. When a software company is doing over $1 billion in annual revenue and its sales and marketing spending is increasing faster than revenue, that's a potential red flag. Sure, the company is winning customers, but those customers are expensive to acquire and potentially unprofitable in the long run.

Database software is sticky. Once a company has committed to using a particular database for a product or internal tool, shuffling around the tech stack is a real pain. MongoDB seems to be banking on this fact, spending heavily to win customers for Atlas. But in a market where unprofitable tech companies are being punished, that's not a strategy that's resonating with investors.