8 ms·
I have seen many people try and shoehorn various problems into MongoDB, when in most cases a relational database would have been better suited. I have yet to s
by collyw 12y ago
I have seen many people try and shoehorn various problems into MongoDB, when in most cases a relational database would have been better suited.
I have yet to see a real use case for Mongo unless you are building a Facebook clone. Can someone suggest when it is actually useful over a properly tuned relational database?
I guess I kind of reached the irrelevance stage just thinking about the sort of problems it would be suited to rather than actually building anything.
- Harrisburg 12y agoThink of an Amazon like product catalogue. I don't want to create a schema in a relational database for that kind of use case. A MongoDB fits as well. Edit: Sorry for my short and unprecise comment. I regret posting it, loosing all my Karma. Yes, of course I would use a schema, but I may use hundreds to get my products presented with all attributes and variants available. There is a set of attributes that will remain for all products, others will vary, some will change and will be dropped. Some may be conditional, depending on size or color. I could model that in RDBMS as well, adding those properties in an additional JSON or something else. Yes, I'm also mainly using relational databases and just wanted to give an example of a use-case for MongoDB. I regret, sorry.
- rjaco31 12y agoCare to elaborate? Beside maybe for the suggestion system, I really don't see what's the gain compared to a relational database.
- BonoboBoner 12y agoProbably the EAV nightmare
- arethuza 12y agoStick JSON in a field within your relational model - best of both worlds.
- BonoboBoner 12y agoI wish I could have a foreignkey within that json.
- CmonDev 12y agoYou can always just stick JSON into a separate table for those cases. So that alone is not an argument.
- collyw 12y agoI wouldn't personally say it fits better. And you are throwing away a ton of useful features that come with a relational database.
- crdoconnor 12y agoSo what happens when you want to list all of the products in a category?
- collyw 12y agoHave a category field or link in the table. Join to it. Joins are not evil, they are damn useful. And well done if your product has become large enough to have scaling problems that can't be solved by a bit of indexing on the joins.
- crdoconnor 12y agoJoins are not supported by Mongo. Or at least, not in any way that isn't tortuous.
- Harrisburg 12y agoquery = db.products.find({'type': 'Film', 'details.actor': 'Keanu Reeves'}) @see: http://docs.mongodb.org/ecosystem/use-cases/product-catalog/ http://docs.mongodb.org/ecosystem/use-cases/product-catalog/ I personally miss Joins in MongoDB - but other vendors support Joins.
- ris 12y agoThere - you're consistently using a field named "type" across your objects - you're using a schema.
- woah 12y agoHA! You got him. A gold star for you sir.
- onion2k 12y agoNot quite. The 'type' in the example is a label for what it contains - it's wholly semantic - as opposed to a field that would exert some sort of constraint such as describing the data type, collation, restraints, etc. Schemaless databases don't completely abandon all forms of organisation because that'd be unusable. They just make the organisation looser. For example, if the user wanted to they could add a record to the products in that example that doesn't have a 'type' (although in the case of that example that probably wouldn't be useful).
- ris 12y ago"I don't want to create a schema..." You are always going to end up creating a schema, whether it's explicit in your tables or implicit within your code. Otherwise you end up with completely heterogeneous data which is impossible to query in any useful way. This is a red herring.
- woah 12y agoNot really. Maybe some products have an attribute that others don't. Maybe you want to query by that attribute. The query won't turn up products without that attribute. Maybe that's ok. Like if you wanted to find all shoes with black laces you can just query for that. Tractors don't even have laces and so they don't come up in the results. In a sql db, every single thing needs to fit into a flat schema with nesting done by relations. Additionally, it's very rigid. Maybe you just don't want to set up a laces table, and 4000 other tables for every little attribute of every product. Of course this is not how you would do it in real life, there are better ways. Mongo is one of those ways. Saying that Mongo is good for nothing is just as dumb as saying that Mongo is good for everything. In 2015, the Mongo backlash is just as tired as the Mongo hype.
- annnnd 12y agoAgreed. That said, optional schema enforcement would be really nice (in my experience, most of the data has a predefined format; so why not define schema and enforce it?).
- gasping 12y agoAre you saying you're using a single MongoDB collection as a dumping ground for all your entities? I hope you're not building a real product that someone has to maintain.
- woah 12y agoI don't actually use Mongo at all, I prefer Postgres. But for loosely structured data, it has a use case. Just like dynamic vs typed languages, there are pros and cons.
- icebraining 12y ago
- rimantas 12y agoI'd say elasticsearch is often used for this kind of tasks.
- annnnd 12y agoLately (and not so lately ;) there has been a lot of bad press about MongoDB. We use it extensively as part of our product (on single servers) and it fills this role nicely. It has a few drawbacks, most notably huge disk space requirements (MongoDB has no compression) which we are hoping to solve with TokuMX (haven't tried it yet). It has some other quirks too, but in general it just... works. And I love using a document DB because it lets you use relations just when they are needed. With relational DBs you often have to use complex joins even for things which should be incredibly simple. On the other hand, I do miss JOINs when I need them (though we solved that on app level). And I would appreciate a way to define schema... :) But would I exchange document DB for relational DB for that? No (for the current project). Maybe I'm getting old, but I really want DB to just work (unlike HBase, at least a few years ago). Other than that, I'm flexible.
- collyw 12y agoPostgres and MySQL just work as far as I am concerned.
- andrea_s 12y agoThe good news is, you can just wait a few weeks and get the possibility to use WiredTiger inside the upcoming 2.8.0. That will solve a few pain points that we've been dragging along for years (namely, document-level locking, disk requirements, multi-document transactions).
- thawkins 12y ago
- JulianMorrison 12y agoI could see its "capped collections" being useful for log analysis.
- nextw33k 12y ago> Can someone suggest when it is actually useful over a properly tuned relational database? In your own question you kind of hint at it. You need a tuned database. NoSQL lowers the barrier to entry for fast persistent data storage with replication. NoSQL doesn't replace SQL databases, it's looking to optimise a use case where transactions are not required. Personally I use Mongo a bit like a cache, sitting in front of a SQL DB. Things that need to be ACID are handed back and forth. Those that don't are kept in Mongo and I get the best of both worlds.
- ddebernardy 12y ago> NoSQL doesn't replace SQL databases, it's looking to optimise a use case where transactions are not required. I'd be curious to know in what contexts anyone would not want transactions. I readily see the case for memcached or equivalent when it comes to caching -- it is very valid, and indeed useful, when slightly outdated data is perfectly acceptable. I can even picture how you might be using MongoDB to do the same, even if you admittedly have me wondering how you're invalidating the mess. For a persistent data store, however, I'm honestly at a loss. In my own experience, transactions are needed as soon as there's a remote possibility that a concurrent write may occur. Even embedded systems need them, when you're threading statements concurrently for performance reasons, or when you're subsequently merging local data with another node. (See CoreData/iCloud bugs for what occurs when you ignore ACID in the latter case.)
- jbergens 12y agoDocument databases normally has atomic updates of a document. This may contain many parts and would require transactions in a relational db. Meaning you kind of get some transactions automatically. Other things are not possible to make transactions around and then you must try to create the app to handle the problems. And some document databases can actually use transactions, like FoundationDb.
- andrea_s 12y agoI'd say a graph database would work much better for building a Facebook clone compared to a document store like MongoDB... And a relational database would still be better than the document store. I've been using Mongo happily to provide online analytics solutions, but the advantage is mostly from the development side, not really from the performance side. On the other hand, this kind of approach is great for attribute matching, which is usually a nightmare to do properly with a RDBMS.
- phpnode 12y ago> I have yet to see a real use case for Mongo unless you are building a Facebook clone People seem to keep making the mistake of building a social network in mongo. It's entirely unsuitable for that. Source: I've helped 3 companies move their social networks from MongoDB to OrientDB when they figured out that MongoDB prevents them from shipping features that users expect, e.g. friend-of-a-friend style queries
- filearts 12y agoWhat has your experience been like in deploying and working with OrientDB? This is a bit of really cool tech that I've been keeping an eye on for some time but haven't gotten around to really playing with it. What server language were you using and where were you deploying?
- phpnode 12y agoOrientDB is very cool software, I find it pretty hard to go back to traditional databases now that I've seen how powerful graphs are, but the cool thing about it is that it's still a document store at heart, so you get all the same advantages of mongo, but with the graph awesomeness on top. It's a fantastic tool, but there are a few quirks that can catch beginners out and the documentation is not stellar. It also requires some configuration tweaking to get the best performance for your workload. I've been using node.js (I develop the official driver - https://github.com/codemix/oriento https://github.com/codemix/oriento), but there's pretty good libraries emerging for other languages too. Most people I've worked with are deploying to AWS, one company was running on the bare metal.
- filearts 12y agoI actually JUST discovered oriento and was absolutely delighted to see a bluebird promise-based api. API looks fantastic. Thanks a ton for creating the lib. Do you have any advise for someone thinking of deploying on GCE? My use-case would be for an online code editor (Plunker, if you've heard of it) with users, projects, packages, collections (of projects), comments and project versions (stored as content-addressable git-compatible objects). I'm also interested in understanding if there is any built-in compression mechanism because I will be storing a large volume of very similar text files. Any hints? Have you used the lucene indexes much? If so, can you do any of the crazy faceting delivered by ElasticSearch?
- Kiro 12y agoI just like being able to insert a random JSON into a collection and query it by any of its properties. Not sure how I would do that with a relational database.
- adamors 12y agoPostgreSQL has full support for JSON [1]. So, quite easily in fact. [1]: http://www.postgresql.org/docs/9.4/static/datatype-json.html http://www.postgresql.org/docs/9.4/static/datatype-json.html
- Kiro 12y agoThanks, I didn't know that. What's the benefit of using PostgreSQL though if the functionality is the same?
- thorin 12y agoYou can do this in Oracle 12 and I think in Postgres. You might want to think about why you need to store unstructured data as part of your application though and query it. If it's expected to live a long time and be queried it should probably be structured. If not you could store it (a serialized object) as a blob if you are just caching some state. https://docs.oracle.com/database/121/ADXDB/json.htm#ADXDB6246 https://docs.oracle.com/database/121/ADXDB/json.htm#ADXDB624...
- TheDong 12y ago> Facebook clone Diaspora is a social network that made the mistake of choosing mongodb for their first iteration. Here's a blog post where one of the involved developers explains why it's not good for that, even: http://www.sarahmei.com/blog/2013/11/11/why-you-should-never-use-mongodb/ http://www.sarahmei.com/blog/2013/11/11/why-you-should-never...
- andrea_s 12y agoTo be fair, this is a poor technical choice that no reputable DBA should ever make... Not really the technology's fault.
- Arnt 12y agoI've used it and been happy. If you want something that's simple to use, know your schema partly but not entirely, and you don't mind losing a few writes, then mongo fits. Relational databases place such emphasis on reliability. Mongo is generally reliable but only two or three nines, and it's simple. For example, if you're collecting sub-cent line items for invoices, you might prefer to collect 99.x% of the line items simply over 100% at greater complication and expense, particularly if you can measure x.
- gasping 12y agoWhat? When would it ever be OK to lose parts of an invoice. Mongo apologists baffle me sometimes. To anyone considering MongoDB, don't be fooled, you probably want to stick with an RDBMS.
- mwj 12y agoWhat are you talking about? We run a 800+ GB mongo cluster and have never lost data.
- Arnt 12y agoWhen the parts are cheap compared to the cost of storing them in a real database. I even know someone who stores invoice items in memcached. Whenever memchached evicts something that hasn't made it onwards to real storage, they lose the ability to invoice the right customer for an ad impression.
- mietek 12y agoThis is satire, right? Right?…
- Arnt 12y agoNot at all. Let me run an example with simple and made-up numbers. Consider two storage solutions used to gather line items to invoices. The line items are ten cents on average. One system is properly ACID, and running it costs one cent per line item on the invoice. The other loses 1% of writes randomly, but its hardware/backup/ops requirements are lower, so it costs just 0.1c/item. The ACID way gives you complete invoices, but you spend 10% of the invoiced amount on the invoices. The lossy way makes your invoices 1% smaller, randomly, but the loss+cost adds up to about 2% instead of 10%. It's like returns on physical goods, really. A random percentage of customers will return goods, you can't control that but you can estimate and monitor it, and optimize if the numbers aren't good enough.
- nevi-me 12y agoHopefully a useful example, would love some comment. I've been building https://rwt.to https://rwt.to and https://movingjoburg.co.za https://movingjoburg.co.za with storage backed by MongoDB. Both are transit apps/websites in South Africa, could be more useful, except that we spend most of our time collecting and capturing data. At the time I was very inexperienced (I guess I'm a bit better now?), but these are the reasons why I chose MongoDB. 1. Geospatial query support out of the box (this is during 2.0-2.2). It's now great with GeoJSON, I store routes and stations as GeoJSON, and querying them is very easy. Compare with PostgreSQL + PostGIS. 2. Some bus services have weird schedule structures, and I needed to be able to generate those schedules, I store schedules as a giant JSON file, and I can query that file to find when the next bus/train is. It's now possible with JSONB in PostgreSQL, but trying to fit that into a relational model wasn't worth the pain at the time, especially when there's always edge cases that I have to cater for at times. 3. To create a pricing engine on rwt.to, I needed a very flexible schema, because I have to cater for many cases (are there bus/train transfers, discounts, and quite different rules for those transfers and discounts). MongoDB gave me the ability to vary my schema in the instances where I needed to store different types of data. I'd rather contend with that than have a table with 100 columns to do the same. To head off on a tangent, in GTFS this data (fares) is computed and stored in the table, but I calculate fares at query-time because there's sometimes a lot of rules to consider, making calculating them and caching them like GTFS unpleasant. 4. Other reasons was because it was pleasant to work with MongoDB + Mongoose.js. This is very important as I'm the sole developer, and due to my line of work, I don't get all the time I need to work on both projects. For my core transit data, I won't reach >20GB even when I manage to collect all the data for South Africa, so I won't have to contend with the 'big data' issues that other users would face. PS: Out of interest, if anyone would like to try rwt.to to see how it works, here are some example links: - https://rwt.to/*mrwF8w0u https://rwt.to/*mrwF8w0u - https://rwt.to/*mrCLEZaE https://rwt.to/*mrCLEZaE - https://rwt.to/*mrOkEDKH https://rwt.to/*mrOkEDKH
- lmm 12y ago> I have yet to see a real use case for Mongo unless you are building a Facebook clone. Can someone suggest when it is actually useful over a properly tuned relational database? Seamless auto-sharding, supported as a first-class use case. Particularly in a cloud environment where you can have your system automatically spin up more hosts as load increases (and take them down as load drops) with zero human intervention, which is really nice. There are plenty of alternatives in that space nowadays (more than when mongo first came out), and reasonable people can disagree over whether to use mongo rather than e.g. cassandra, riak, or shonky third-party clustering addons for mysql/postgresql, but I've yet to see an affordable relational database with out-of-the-box auto-sharding support that comes anywhere close to what mongo offers. (Also, first-class support for async-io clients. This is about client libraries rather than the server itself, and purely an artefact of when mongo was released, but if you're calling e.g. PostgreSQL from the JVM, most of the libraries are oriented towards blocking JDBC which is "good enough" (there are valiant efforts like https://github.com/mauricio/postgresql-async https://github.com/mauricio/postgresql-async but you can't use them with established higher-level libraries). Whereas every mongo library offers a callback- or future-based API, and the higher-level libraries are built around this)
- girvo 12y ago> but I've yet to see an affordable relational database with out-of-the-box auto-sharding support that comes anywhere close to what mongo offers. FoundationDB is a bit weird, but it handles automatic scaling-out, and has an ANSI SQL interface (backed onto a K-V store): https://foundationdb.com/key-value-store/white-papers/scalability https://foundationdb.com/key-value-store/white-papers/scalab... Caveat: I've not used it for more than hobby stuff yet, but it's a fascinating bit of technology!
- lmm 12y agoSounds interesting, but frankly I wouldn't trust anything so young in production yet. For all mongo's faults, at this point the pitfalls are reasonably well-known and there are enough serious organizations using it at scale to give a certain level of confidence.
- deepGem 12y agoMongoDB is not at all good for Social networks or anything resembling a graph. You are better off with Titan (horizontal scaling) or Neo4j (vertical scaling). Neo4j offers this great ability to query by a path, which no other database offers.
- enobrev 12y agoI generally agree in regards to shoehorning data into MongoDB. I don't agree that a facebook clone fits appropriately. When thinking through a project, my mental model generally self-configures into third-normal form, which is to say I literally think in the manner of a relational database. That said, I have found one specific use-case where it has incredibly worked well, which is as a JSON-based file system in which I can query into the document structure to find the records and data I need en-masse with very simple queries. A project I've been working on for a few years has its own custom schema that fits far better into a JSON hierarchy than a relational one. In this specific system there are very few records (compared to our primary RDBMS which has millions), and when not being explicitly maintained, the files are generally static. The single-collection database in question with a few hundred JSON objects would likely have to be split into at least 10 tables with thousands of records each. When it comes to using said "files" in production, I index the objects into memory for quick retrieval. In order to populate said cache, MongoDB allows me to query into the JSON file structure and retrieve the necessary "files" very simply into however many indices I need. And that's where it has shined in my experience; Not as a live read-write datastore for production use, but as read-heavy storage for a relatively small amount of JSON data with a deep hierarchy that would require an annoying amount of joins and subqueries for otherwise simple queries. I've also tried it out with our multi-system logging system using capped collections (JSON formatted messages transported and collected with rsyslog). But we grew beyond its limits almost immediately and ended up in far more manageable territory with kibana / elasticsearch.
- pjmlp 12y ago> Can someone suggest when it is actually useful over a properly tuned relational database? Maybe when developers don't want to bother to learn SQL? On my CS degree we got proper introduction to SQL and the relational algebra behind it, so for me it is just a tool, not a scary monster. I really love the data integrity options I have at my disposal with relational databases. So for me this all NoSQL fad never made much sense. Then again, I never had to deal with a Facebook like scale problem, only daily reports from mobile network operators across their whole network elements.
- octix 12y agoIt's not about Facebook clone, they still use MySQL for some functionality (i believe), but not as RDBMS but more like NoSQL... NoSQL means model your data in a different way, the way you'll be using it. For some it makes more sense, for some may not. For example, compare implementation of a tagging system in mongo and any other RDBMS, which one is easier?
- pjmlp 12y ago> For example, compare implementation of a tagging system in mongo and any other RDBMS, which one is easier? As I said, I never bothered with NoSQL so I cannot properly answer it.
- khalidmbajwa 12y agoWe are building a music streaming website. Think of it as a Spotify for Pakistan and Mongo has been wonderful for the kind of Data Structure we have. Its perfect for a catalogue like structure where objects can very easily nest inside each other. Each Artist has multiple albums, and multiple artists have multiple songs. All of this nestles very neatly inside eachother, and when i want a song, i almost always need its album and artist data, so i can very easily get that. Mongo is blazing fast on such kind of nested data structures. The only slight problems is where you have playlists and need to reference songs for a certain Artist. That could be countered by Data Duplication, since the song artist data etc once entered will very rarely change. So for us it makes perfect sense. You really need to understand what your data model is, and what you want from it, and then Mongo will be your friend, other than that it will cause you a world of pain.
- fragmede 12y agoHow does that hierarchical model work when songs or albums have more than one artist? Why does a traditional relational db fail for such a well-defined data model? I mean, there's nothing about 'given an song (id), retrieve artist and album' that would make mongo inherently better.
- no_future 12y agoHave you ever used a relational database? It would be much easier and faster for a dataset like this. The general consensus on the use case for something like MongoDB is actually the opposite of what you opine. It works well for large, loosely defined datasets where many fields can be optional or empty, for example something like patient medical data, with few or very basic relations between objects. I don't think that anyone besides the "evangelists"(shills selling snake oil) would tell you to use something like Mongo if you have a well-defined and predictable dataset.
- jbergens 12y agoFor some systems the development time is much shorter with a document db (or a graph db) than with a relational db. That can be more important than pure performance. Basic scalability is also usually better since it often easy to shard data across servers.
- avasdvasdv 12y ago> I have seen many people try and shoehorn various problems into MongoDB MongoDB is easy and was used by web "developers" too lazy to learn SQL and RDBMs. MongoDB is fine if you don't really care about the data. If you don't need ACID compliance and can afford to lose transactions.
- collyw 12y ago/dev/null would be faster in those cases