c# - Azure Document DB UpdateDoc -


i starting off azure document db. trying update existing document. when use following query works:

dynamic team2doc = client.createdocumentquery<document>(documentcollection.documentslink).where(d => d.id == "t002").asenumerable().firstordefault(); team2doc.teamname = "updated_team_2"; await client.replacedocumentasync(team2doc); 

but if use below code:

dynamic team2doc = client.createdocumentquery<document>(documentcollection.documentslink).where(d => d.teamname== "team1").asenumerable().firstordefault(); team2doc.teamname = "updated_team_2"; await client.replacedocumentasync(team2doc); 

i error:

"the best overloaded method match 'microsoft.azure.documents.client.documentclient.replacedocumentasync(microsoft.azure.documents.document, microsoft.azure.documents.client.requestoptions)' has invalid arguments"

is there anyway retrieve document 1 of properties , update document?

the clause trying query property teamname not exist in document class.

changing type of queryable data model should fix it.

for example, have following data model:

public class employeedocument : document {         // other properties may have defined ....       public class string teamname       {                 {             return this.getvalue<string>("teamname");         }          set         {             this.setvalue("teamname", value);         }      } } 

then can modify query this:

var team2doc = client.createdocumentquery<employeedocument>(documentcollection.documentslink).where(d => d.teamname== "team1").asenumerable().firstordefault(); team2doc.teamname = "updated_team_2"; await client.replacedocumentasync(team2doc); 

note have use employeedocument, instead of document class, while creating document queryable. let query on employeedocument properties.

sql version

creating document model each of existing data models may not feasible if have large number of data models. in case may want try out sql query syntax.

refer aravind's answer in post. example uses deleting documents, can modified update them too.


Popular posts from this blog