Is there a simple/any solution for putting JSON representation of Document data (without DocDb native properties like _rid etc.) into response (in stored procedures) or is there a solution somewhere in Microsoft.Azure.Documents namespace?
2 Answers
You can use JavaScript's delete operator to strip out DocumentDB's native properties. Take a look at this thread: How do I remove a property from a JavaScript object?
Something like this should work:
delete doc._rid;
delete doc._ts;
delete doc._etag;
getContext().getResponse().setBody(doc);
1 Comment
Chris Hermut
Thanks for you answer. There's quite a few solutions when it comes to removing properties from an object (sproc, inside the controller(MVC wise) etc.) I was just hoping for a "native" solution.
I was having the same question. I found this way (in C#):
dynamic d = Newtonsoft.Json.Linq.JObject.Parse(doc.ToString());
string versionData = d["Employees"]["@version"];
string employeeNameData = d["Employees"]["@name"];
Where "Employees" is the Document name (i.e., table name in Sql terms), and version is a attribute of that document.
This way you can make a generic query over any data stored internally in the document. Hope this helps! :)
1 Comment
Deb
Of course you can also do the following directly: dynamic jsonObj = doc; (where doc is the Microsoft.Azure.Documents.Document) but, then you can't do the following: string versionData = d["Employees"]["@version"]; and you have to do: string versionData = d.Employees.["@version"]; which makes it a bit un-generic