kekestan
(Gleb)
1
I have a sharded collection of documents. Example of a single document:
{
_id: {
"a": "1",
"b": "1",
"c": "1"
},
"someData": "abc"
}
Hashed shard key – “_id.a”
I have two main scenarios:
- updating document;
- querying documents.
Question №1: In first scenario i need to update a single document by _id. Will MongoDB treat this operation as targeted to a single shard?
Here i’m not providing an explicit sharding key, but according to a query plan this operation hits only one shard.
Question №2: In second scenario i would like to filter documents by _id using $in operator. All provided documents for $in operator have same value for field “_id.a”. Is it possible make MongoDB to treat this query as targeted to a single shard?
Of course i have a workaround to query by a shard key and then filter data in code, but i would like to get it by a single query in MongoDB.