Reputation: 39
I have a JSON document which I am passing to DocumentDB stored procedure. Is there a way I can add more properties to document in store procedure
Passed to DocumentDB:
{
"id": "Authentication",
"name": "All users must be authenticated before being authorized for any access to service data",
"type": "Control"
}
Expected changes in Stored Procedure:
{
"id": "Authentication",
"accountId": "Test",
"versions": [
"name": "All users must be authenticated before being authorized for any access to service data",
"type": "Control",
"tags": [],
"links": []
]
}
Upvotes: 1
Views: 2004
Reputation: 8119
You can manipulate the object (add / remove properties) using plain JavaScript syntax.
And then use the DocumentDB server-side JavaScript SDK to create the document.
Here's an example Stored Procedure to get you started:
function transform(doc) {
var collection = getContext().getCollection();
var response = getContext().getResponse();
// Add new accountId and versions fields.
doc.accountId = "Test";
doc.versions = {
name: doc.name,
type: doc.type,
tags: [],
links: []
};
// Remove old name and type fields.
delete doc.name;
delete doc.type;
// Create the document.
collection.createDocument(collection.getSelfLink(), doc, function(err, result) {
if(err) throw err;
// Return the resulting document back as the response.
response.setBody(result);
});
}
Upvotes: 3