How to update a field in sharded environment in mongodb using C# driver I have successfully done loading in sharded environment. It is working fine. But when I do update in sharded environment, I am getting the error as :

WriteConcern detected an error
 'update { q: { IsTagged: "0" }, u: { $set: { IsTagged: "1" } }, multi: false, upsert: false } does not contain _id or shard key for pattern { JobId: "hashed" }'. 
 (Response was { "ok" : 1, "code" : 61, "err" : "update { q: { IsTagged: \"0\" }, u: { $set: { IsTagged: \"1\" } }, multi: false, upsert: false } does not contain _id or shard key for pattern { JobId: \"hashed\" }", "n" : NumberLong(o), "updatedExisting" : false }).


I need to update the value of Istagged from 0 to 1 . But it is showing as read concern error.I can get the point that the error is due to not giving the shard key. The Code which I am using is :

var query = Query.EQ("IsTagged", "0");
var update = Update.Set("IsTagged","1");
collection.Update(query, update);


I am using C# driver to communicate with mongodb. I dont know how to mention shard key in this coding.
All targeted updates (multi: false so targeting a single document) must contain enough information to target a single document in order to be routed correctly (i.e. the shard key, or the _id of the document being targeted).

To understand why, consider what would happen with your attempted update. You have said (by stating multi: false that you only want one document to be updated.  

First, because you have not specified the _id value of the document (unique value), if the query is broadcast to all shards, there could be multiple resulting updates (each shard will only update one document but if you have 3 shards, 3 docs could be updated total). Hence that is rejected.

The other option is to route the update operation only to a single shard.  But to do so, you must specify the JobId (your shard key) as part of the criteria for your update.  Then the operation would not need to be broadcast to all shards, it could be routed to a single shard and your original criteria (only update one such document) could be satisfied.

If your intent is to update more than one document, then simply change multi to true.  If not, then you need to be more specific about what single document you want to update.