# query data via mongos, when one shard in MongoDB Sharded cluster is not available?

**URL:** <https://forums.percona.com/t/query-data-via-mongos-when-one-shard-in-mongodb-sharded-cluster-is-not-available/6773>\
**Category:** Percona Server for MongoDB\
**Created:** [January 4, 2019, 10:12am UTC](https://forums.percona.com/t/query-data-via-mongos-when-one-shard-in-mongodb-sharded-cluster-is-not-available/6773 "2019-01-04T10:12:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![openkin](https://avatars.discourse-cdn.com/v4/letter/o/ee59a6/32.png) [@openkin](https://forums.percona.com/u/openkin)\
**Post date:** [January 4, 2019, 10:12am UTC](https://forums.percona.com/t/query-data-via-mongos-when-one-shard-in-mongodb-sharded-cluster-is-not-available/6773/1 "2019-01-04T10:12:27Z")

</div>

Hi community!  
I want to query data via mongos, when one shard in MongoDB Sharded cluster is not available, it should be possible according to docs

[url][https://docs.mongodb.com/…/…/troubleshoot-sharded-clusters/…[/url]](https://docs.mongodb.com/%E2%80%A6/%E2%80%A6/troubleshoot-sharded-clusters/%E2%80%A6%5B/url%5D)

“However, the data on all other shards will remain available, and it is possible to read and write data to the other shards. However, your application must be able to deal with partial results, and you should investigate the cause of the interruption and attempt to recover the shard as soon as possible.”

But in my case i always get “errmsg” : “None of the hosts for replica set XXX could be contacted.”, despite the fact i actually asked data, which are located in “live” shard (replica set).

Any ideas ?  
Mongodb version - 3.2.17

---

<div class="post-metadata">

**Author:** ![Vinodh\_Krishnaswamy](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.percona.com/vinodh_krishnaswamy/32/46_2.png) [@Vinodh\_Krishnaswamy](https://forums.percona.com/u/Vinodh_Krishnaswamy)\
**Post date:** [February 23, 2019, 6:14am UTC](https://forums.percona.com/t/query-data-via-mongos-when-one-shard-in-mongodb-sharded-cluster-is-not-available/6773/2 "2019-02-23T06:14:40Z")

</div>

Hi,

> [@](#):
>
> > it should be possible according to docs

Yes you are right. You could fetch data from the cluster even a shard is down. But it is possible only when mongos could target those data from the live shards through shard keys. That means, the query should include the shard key. If not, mongos will broadcast the query request to all shard and receives error when one is not up.

You can read more about this target vs broadcast requests here - [https://docs.mongodb.com/manual/core/sharded-cluster-query-router/index.html#targeted-operations-vs-broadcast-operations](https://docs.mongodb.com/manual/core/sharded-cluster-query-router/index.html#targeted-operations-vs-broadcast-operations)

For example: Insert some value in mongos and here field “id” is shard key.

```auto
mongos> db.testData.insert({id: 100001, name: "Alex"})
WriteResult({ "nInserted" : 1 })
mongos> db.testData.insert({id: 100002, name: "Julie"})
WriteResult({ "nInserted" : 1 })

```

Now shutdown one shard:

```auto
[root&#64;vinodh-krishnaswamy ~]# mlaunch stop shard03
sent signal 15 to 3 processes.

```

Now check the data again from mongos with or without shard key and check the results:

```auto
mongos> db.testData.find({id:100001})
{ "_id" : ObjectId("5c712e53831dfa8c69cf274d"), "id" : 100001, "name" : "Alex" }

```

```auto
mongos> db.testData.find({name:"Alex"})
error: {
"$err" : "ReplicaSetMonitor no master found for set: shard03",
"code" : 10009,
"shard" : "shard03"
}

```

Hope this helps you.
