Stefan Cebulak Stefan Cebulak - 1 year ago 179
C# Question

Azure DocumentDB - Insert object to document array?

I'm developing a simple question-answers forum. I want to use Azure DocumentDB.

How can i add an answer to existing question document in DocumentDB?

In my case i've done a list of answers of the same type as question:

public List<Announcement> { get; set; }

My document object looks as follows:

public class Announcement
[JsonProperty(PropertyName = "id")]
public string ID { get; set; }

[JsonProperty(PropertyName = "userid")]
public int UserID { get; set; }

[JsonProperty(PropertyName = "username")]
public string UserName { get; set; }

[JsonProperty(PropertyName = "useripaddress")]
public string UserIPAddress { get; set; }

[JsonProperty(PropertyName = "body")]
public string Body { get; set; }

[JsonProperty(PropertyName = "tags")]
public List<string> Tags { get; set; }

[JsonProperty(PropertyName = "datecreate")]
public DateTime DateCreate { get; set; }

[JsonProperty(PropertyName = "isedited")]
public bool IsEdited { get; set; }

[JsonProperty(PropertyName = "dateedit")]
public DateTime DateEdit { get; set; }

[JsonProperty(PropertyName = "imageaddonid")]
public string ImageAddonId { get; set; }

[JsonProperty(PropertyName = "imageaddonsource")]
public string ImageAddonSource { get; set; }

[JsonProperty(PropertyName = "answers")]
public List<Announcement> { get; set; }


I don't see any update methods in DocumentClient :/.

Answer Source

For me, you need to use the ReplaceDocumentAsync method in order to update your document.

As far as I can tell you need to be replacing the entire document; because when you change something you update the entire document not a part of it.

You can check the documentation about the method here

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download