Should I use Mongo?

Asked bycoralee


Recently, I hear more and more mentions about NoSQL and MongoDB in particular. I was interested in the topic, but I still can’t find the information that interests me, so I’ll ask here - probably many have already managed to experiment and maybe develop serious high-loaded applications in conjunction with MongoDB.
I will warn you in advance if somewhere I made a mistake regarding MongoDB - I did not specifically. I just didn’t even try to work with her, but just read the articles on Habré, but those examples that lie on the office.

Now I am developing a teaser network. The task, seemingly trivial at first glance, actually comes out quite clever in terms of organization of the database structure. A huge number of links, a set of intermediary tables for MM connections, etc ... What attracted me to the idea of ​​MongoDB is its principle of building links. Question number 1:
Is working with MongoBD really more costly in the presence of a bunch of links? Well, at least in the simplest example (I will write on “pseudo SQL”) - a selection of 2 tables connected by a MM-relationship through an intermediate table:
table sites (
id int primary key auto_increment,
url varchar

table categories (
id int primary key auto_increment,
name varchar

table sites_categories (
site_id int,
category_id int

The task is to list the sites and categories in which it is:


while (SITE = mysql_result ...)
// display site data
SELECT * FROM categories WHERE id IN (SELECT category_id FROM sites_categories WHERE site_id = SITE)
// in the cycle we display categories

Also I'm interested in, is it possible to work simultaneously with MySQL and MongoDB? Or rather, how it will be right? I don’t want to completely transfer the database to Mongo, only some very special sections, the load on which is higher than what I want.

I also read that you can safely store files in MongoDB - is this really the case and what would be better - store it in the old fashioned way in a special folder with subdirectories by username / id of users, or use MongoDB? (for example, in this situation: there are about 1k users, each one has 40-50 small pictures. Pictures are given in a quantity of about 100-150 per minute.

PS: I apologize for any inaccuracies in the questions, unnecessary or unspoken information about the needs and the current state of affairs, the development of database structures is not my main advantage ...


I apologize for the offtopic, but in your examples like
 SELECT * FROM categories WHERE id IN (SELECT category_id FROM sites_categories WHERE site_id = SITE)
JOIN is essentially not used ???

And try to store pictures on Amazon
Could there be hope of replication? Then JOIN cannot be used. - nour almnaizel
is a pseudo-sql, I wrote :)
It’s just that I’m still not very good with Join’s, if I don’t have it at hand, that's why I wrote it just to get the message across :) - priti raja
& gt; Just with Join'ami, I’m not very good at it so far

Great approach: I don’t understand join'ami, then I’ll deal with mongodb. - liesbeth workman
I understand, though not as well and quickly as we would like.
What is the connection between my understanding of JOINs and the desire to try MongoDB? - kim stroup
no, on the go
I wrote stupidity - stephen barker
carol estes
Be attentive! The principles of building a database in Mongo are different. You need to understand how it stores objects and what loads the object entirely.
In general, IMHO, many-to-many links are not Mongo's strengths (and other NoSQL databases with which it is familiar). They work most effectively with embedded objects, that is, one-to-one relationships and one-to-many one-way relationships.
so after all M-M is two 1-M ... Why is there such a difference? - sarah kahn
Mongo is effective when one object (or an array of objects) can be nested in another and the first without the second has no meaning. Examples - account profile, comments for posts, addresses and phone numbers in the address book. In this case, the associated data is stored together and, roughly speaking, one search by identifier (“primary key”) and object retrieval (with different nesting depth depending on the purpose of the request) is carried out - the efficiency can be compared with denormalized RDBMS. If references ("foreign keys") are used, then such operations need to be made a little - as a matter of fact from JOIN differs nothing. Although, of course, you can denormalize the Mongo base or use your name as the “primary key” of the categories, and their URLs as the primary key of the sites (then the typical tasks are “displaying the site’s details and the names of its categories” and and URLs of its sites "will be carried out in one operation) - hampton
For Mongo, each site must include a category_id with a category listing. That is, for nosql, the connection of many-to-many is realized by storing in one of the objects a complete enumeration of relations to the second.
taja sparks
To get started, read document

Here's an example of what it might look like.

And request for example to get all teasers for Moscow where there are still clicks, for example, more than 10

Regarding reliability and speed, honestly xs, has not yet experimented globally, then you will have to do research yourself, I can say one thing, the speed of implementation and expansion pleases :)
Thanks for the examples. Tell me, are they, by chance, taken from a real teaser network? If so, how are things going with Mongo? - suzanne benson
Not-not, dashed the structure in a couple of minutes for logical reasons :) - missninelien
michael webster
Again offtopic:
In general, I was modifying the teaser network with one ... There is no targeting, but about 90 million hits of teasers worked fine per day (now the turnover was down to about 50 million). It all revolves on one single rather powerful server (and the second server is just pictures).
There, all the data on teasers banned by aypishnikas, at the price per impression / click, is collected from memkes. If for some reason there is no data in the memkesh (Eviction, for example, or a cold start), then only then it is taken from the database and immediately put back into the memkes. The statistics for the last minute is also put into the memory and once a minute the data is collected from it, computed, and the aggregate statistics is put into MySQL. Those. in fact, to unscrew the teasers, the database does not move at all.
(Before memkesh, they used the file system for this data - they flew almost the same way as on memoksh)

But you may not be suitable because I don’t really understand how targeting can be implemented there.
The method of organizing it practically does not change the usefulness of your comment - the IP ranges data is simply stored locally, and when selecting teasers for display, a +1 condition is added so that the client's IP is in the campaign range from which teasers are selected. If interested - I can tell you in detail :)
Regarding the idea of ​​memkesh - thanks, it was planned to add work with it before launch. - clarissa dyer
Configuring Apache .htaccess Main directory :: Stretching a container with two blocks with float: left :: Index across the integer field in PostgreSQL :: Where can I find volunteers to develop an international non-profit charity project? :: Calibration of the battery Nokia N82?
Leave Repply forShould I use Mongo?
Useful Links