Search code examples
mongodbelasticsearchsharding

Is there any option similar to ElasticSearch's routing in MongoDB?


According to the ElasticSearch routing parameter document,

When executing a search, it will be broadcasted to all the index/indices shards (round robin between replicas). Which shards will be searched on can be controlled by providing the routing parameter. For example, when indexing tweets, the routing value can be the user name.

In such a case, if we want to search only on the tweets for a specific user, we can specify it as the routing, resulting in the search hitting only the relevant shard.

$ curl -XGET 'http://localhost:9200/twitter/tweet/_search?routing=kimchy' -d '{
    "query": {
        "filtered" : {
            "query" : {
                "query_string" : {
                    "query" : "some query string here"
                }
            },
            "filter" : {
                "term" : { "user" : "kimchy" }
            }
        }
    }
}
'

So, as i am starting with MongoDb, i am looking out any similar option if available?


Solution

  • The equivalent concept in MongoDB is the shard key. If mongos can determine from the shard key that only some (or one) of the shards holds data relevant to the query, only those shards will be accessed.