title: ERROR Caused by: com.mongodb.MongoCommandException: Command failed with error 61: query in command must target a single shard key on server
body: <p>Getting this error "query in command must target a single shard key' on server " while doing <code>collection.count(queryParams);</code>. In Java, how can I read all the data from all the shard/multiple shards? We are using Microsoft Azure Cosmos DB.</p>
  
  <pre><code>[ERROR] Caused by: com.mongodb.MongoCommandException: Command failed with error 61: 'query in command must target a single shard key' on server ".
  </code></pre>
  
  <p><strong>Sample Code:</strong></p>
  
  <pre><code>MongoCollection&lt;Document&gt; collection = database.getCollection(eventsCollectionName); 
  
  Bson queryParams = Filters.and(
                          Filters.eq("mysystem.name", dmsEvent.getSystem().getName()),
                          Filters.eq("mysystem.environment", dmsEvent.getSystem().getEnvironment()),
                          Filters.eq("mymessage.type", dmsEvent.getMessage().getType()),
                          Filters.eq("myuser.syscode_id", dmsEvent.getUser_id().getSyscode_id()),
                          Filters.eq("myuser.condition_id", dmsEvent.getUser_id().getCondition_id()));
  
  //This line is erroring out
  long recordCount = collection.count(queryParams);
  </code></pre>
  
  <p><strong>Sample Cosmos DB Collection Document:</strong>
  Shard key is "/partitionKey". </p>
  
  <pre><code>{
      "_id" : ObjectId("5ab85424a43e6b11916ff6c3"),
      "myuser" : {
          "syscode_id" : 1,
          "condition_id" : 1
      },
      "mysystem" : {
          "name" : "4DL",
          "environment" : "D"
      },
      "mymessage" : {
          "type" : "A",
          "occurance_count" : 1,
          "rolltime" : "2018-03-25T18:00Z",
          "timestamp" : "2018-03-25T18:00:11.150379Z"
      },
      "mydata" : {
          "count" : "12",
          "slot" : [
              {
                  "length" : null,
                  "value" : "FF00"
              }
          ]
      },
      "partitionKey" : "18",
      "timeToLive" : 777600,
      "_ts" : "2018-03-26 02:00:04.495"
  }
  </code></pre>