Answer the question
In order to leave comments, you need to log in
MongoDB sampling on sharding, searching in parallel for all nodes?
Good day to all!
Interested in the question. For example, I implemented MongoDB auto-sharding for several nodes, let's say 10.
There is a "users" collection with 20 million documents that stores all users. They are spread over all nodes by id. And here it is necessary to register a new user with a unique username. We make a request:
db.posts.find({"username":"..."})
if it returns 0 records, then register with this username.
Here is the question, will MongoDB run through all the nodes and records in turn or in parallel? It's just that this solution doesn't seem to be as productive.
The same example can be given with post comments, the comments are spread over the nodes, and in order to display them all MongoDB searches for them among all the nodes and displays them?
Answer the question
In order to leave comments, you need to log in
Why do find? You may have a situation where two users with the same name can register at the same time. And it turns out that find will return false, but when inserting data, someone will see an error. It's better to index on the username field and just insert the data. If the data is inserted, then ok, if not, then the username is invalid. It turns out that you will always run one request, instead of two.
On the topic:
a search by a unique index will immediately get to the desired shard without any additional scans.
In parallel, of course.
If it ran in turn, there would be no sense in the shard at all.
They are spread over all nodes by id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question