Hello, I hope you’re all doing well.
NOTE: the mongodb’s version in question is 3.0
We have a sharded setup of mongodb across several nodes.
Let’s say there is a collection events
with documents like:
{
user_id: <ObjectId>,
company_id: <ObjectId>,
event_id: <string>,
start_date: <datetime>,
end_date: <datetime>
}
The index used as a shard key is {company_id: 1, user_id: 1, event_id: 1}
. Also, there is a multikey index on this collection {company_id: 1, user_id: 1, start_date: 1, end_date: 1}
Now, the query like {company_id: ...., user_id: ...., start_date: ...., end_date: ....}
comes in. (NOTE: the query doesn’t have the event_id
field).
My questions are:
-
Would
mongos
be ALWAYS sending this query to all shards because it couldn’t figure out the exact shard without theevent_id
field? -
The same situation, but with the shard key by
{company_id: 1, user_id: 1}
. Will mongos be asking only a single shard for data without unnecessary requests to other shards?
Thank you.