繁体   English   中英

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

[英]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"   
        }
      ]
    }
  ]
}
  • 我想在aid的基础上取得记录。

  • 50record可以有多个对象, licenses也可以有多个对象。

  • 我正在构建查询"SELECT * FROM orders o WHERE o['50records'][0].licenses[0].aid='someAid'"
  • 如何在所有可用对象中循环使用这些50recordslicenses来搜索aid

以下是我的商店程序:

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"

谢谢!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM