0

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?

Community
  • 1
  • 1
Chris Hermut
  • 1,708
  • 3
  • 17
  • 32
  • I have edited your title. Please see, "[Should questions include “tags” in their titles?](http://meta.stackexchange.com/questions/19190/)", where the consensus is "no, they should not". – John Saunders May 31 '15 at 00:16

2 Answers2

2

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);
Community
  • 1
  • 1
Aravind Krishna R.
  • 7,885
  • 27
  • 37
  • 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. – Chris Hermut May 31 '15 at 08:53
2

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! :)

Deb
  • 737
  • 1
  • 5
  • 20
  • 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 – Deb Aug 17 '15 at 08:09