Cosmos-DB/Document-DB中如何使用Loop执行存储过程?

How to use Loop to execute store procedure in Cosmos-DB/Document-DB?

我 JSON 喜欢

{
  "id": "58d99ca3231f13b9ecbbbca4",
  "50records": [
    {
      "aomsLineNbr": 1,
      "licenses": [
        {
          "productKey": "84fc2cde-9735-4cea-b97a-3cd627d3d0a5",
          "aid": "someAid"   
        }
      ]
    }
  ]
}

下面是我的存储过程:

function getOrdersByAidCollection(aid){
var context = getContext();
var collection = context.getCollection();
var link = collection.getSelfLink();
var response = context.getResponse();

var query = "SELECT * FROM orders o WHERE o['50records'][0].licenses[0].aid='"+aid+"'";

var isAccepted = collection.queryDocuments(collection.getSelfLink(),query,
function (err, feed, options) {
    if (err) {
        return errorResponse(400, err.message);
    }
    if (!feed || !feed.length){
        return errorResponse(400, "no orders doc found");
    }else { 
       getContext().getResponse().setBody(JSON.stringify(feed));
    }
});

    if (!isAccepted){
        return errorResponse(400, "The query was not accepted by the server.");
    }


}

我需要在哪里以及如何放置循环??

任何帮助都将不胜感激!

谢谢

为什么需要循环?这看起来像一个查询问题。你能试试这样的查询吗:

SELECT VALUE r
FROM orders c
JOIN r in c["50records"]
JOIN li in r.licenses
WHERE li.aid = "someAid"

谢谢!