Add new properties to DocumentDB Document in Stored procedure

眉间皱痕 提交于 2019-12-06 14:53:25

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);
  });

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!