我有类似 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'”
- 如何循环那些
50records
和licenses
以在所有可用对象中搜索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"
谢谢!
关于javascript - Cosmos-DB/Document-DB中如何使用Loop执行存储过程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44392568/