Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What operations are cheap/expensive in mongodb?

Tags:

mongodb

I'm reading up on MongoDB, and trying to get a sense of where it's best used. One question that I don't see a clear answer to is which operations are cheap or expensive, and under what conditions.

Can you help clarify?

Thanks.

like image 653
Abe Avatar asked Dec 19 '11 13:12

Abe


People also ask

What are the disadvantages of MongoDB?

Cons: Data size in MongoDB is typically higher due to e.g. each document has field names stored it. less flexibity with querying (e.g. no JOINs) no support for transactions - certain atomic operations are supported, at a single document level.

Is MongoDB cloud expensive?

MongoDB Atlas Pricing AdviceIt's not cheap or expensive. For smaller companies, it's definitely expensive."

How does MongoDB pricing work?

MongoDB Atlas offers a perpetual free tier and usage-based pricing for as little as $9/mo for a shared instance or $60/mo dedicated. You're only charged per instance hour actually running and a flat rate for data transfer, so changing configurations is no big deal.


2 Answers

It is often claimed that mongodb has insanely fast writes. While they are not slow indeed, this is quite an overstatement. Write throughput in mongodb is limited by global write lock. Yes, you heard me right, there can be only ONE* write operation happening on the server at any given moment.

Also I suggest you take advantage of schemaless nature of mongodb and store your data denormalized. Often it is possible to do just one disk seek to fetch all required data (because it is all in the same document). Less disk seeks - faster queries.

If data sits in RAM - no disk seeks are required at all, data is served right from memory. So, make sure you have enough RAM.

Map/Reduce, group, $where queries are slow.

It is not fast to keep writing to one big document (using $push, for example). The document will outgrow its disk boundaries and will have to be copied to another place, which involves more disk operations.

And I agree with @AurelienB, some basic principles are universal across all databases.


Update

* Since 2011, several major versions of mongodb were released, improving situation with locking (from server-wide to database-level to collection-level). A new storage engine was introduced, WiredTiger, which has document-level locks. All in all, writes should be significantly faster now, in 2018.

like image 96
Sergio Tulentsev Avatar answered Oct 01 '22 12:10

Sergio Tulentsev


From my practice one thing that should mentioned is that mongodb not very good fit for reporting, because usual in reports you need data from different collections ('join') and mongodb does not provide good way to aggregate data multiple collections (and not supposed to provide). For sure for some reports map/reduce or incremental map/reduce can work well, but it rare situations.

For reports some people suggest to migrate data into relations databases, that's have a lot of tools for reporting.

like image 29
Andrew Orsich Avatar answered Oct 01 '22 13:10

Andrew Orsich