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?

1

2 Answers 2

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);
Sign up to request clarification or add additional context in comments.

1 Comment

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

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.