Is it possible to query MongoDB several times per request?

Based on the background of RDBMS, I always had the impression “Try your best to use one query, considering it effective”, which means that it is expensive for every query you make in the database. When it comes to MongoDB, it looks like it might not be possible because you cannot join tables.

I understand that it does not have to be relational, but they also push it towards goals such as blogs, forums, and all that I can find RDBMS with.

There are some freezes that I tried to understand the effectiveness of MongoDB or NoSQL as a whole. If I wanted to get all the "messages" associated with specific users (as if they were grouped) ... using MySQL, I would probably make several joins and get them with it.

In MongoDB, assuming I need separate collections, would it be efficient to use large $ in: ['user1', 'user2', 'user3', 'user4', ...]?

After some time, does this method slow down? Should I include 1000 users? And if I needed to get a list of messages related to users of X, Y, Z, it would be efficient and / or fast to use MongoDB:

  • Get an array of users
  • Get user messages in an array of users

2 requests for one request. Is this bad practice in NoSQL?

+17
database mysql mongodb nosql
Mar 01 '11 at 16:25
source share
1 answer

To answer Q on $ in ....

I conducted several performance tests with the following scenario:

~ 24 million documents in the collection
Search 1 million of these documents based on key (indexed)
Using the CSharp driver from .NET

Results:
Request 1 at a time, single threaded: 109s
Request 1 at a time, multi threaded: 48s
Request 100K at a time using $ in, single threaded = 20s
Request 100K at a time using $ in, multi threaded = 9s

Significantly better performance using large $ in (limited by the maximum request size).

Update: Following the comments below on how $ in executes with different block sizes (multi-threaded requests):

Request 10 at a time (100,000 lots) = 8.8s
Request 100 at a time (10000 lots) = 4.32s
Request 1000 at a time (1000 lots) = 4.31s
Request 10,000 at a time (100 lots) = 8.4s
Request 100,000 at a time (10 batches) = 9 s (for the initial results above)

So it seems like a sweet thing for how many values ​​should be included in the $ in clause compared to the number of rounds.

+32
Mar 01 '11 at 16:38
source share



All Articles