英文:
How to fetch distinct items with all their properties in cosmos db?
问题
我正在使用TypeScript创建Azure函数。其中一个输入绑定是Azure Cosmos DB容器。在我的function.json中,我已经有一个SQL查询来筛选结果。我知道很多结果在companyName属性上有重叠的属性,换句话说,它们是重复的。
有人知道如何根据companyName属性只获取不同的项吗?
我已经尝试了以下方法,但它们都导致错误。
"sqlQuery": "SELECT DISTINCT * FROM c"
"sqlQuery": "SELECT DISTINCT VALUE FROM c"
"sqlQuery": "SELECT DISTINCT * ORDER BY c.companyName FROM c"
英文:
I am creating an Azure Function in Typescript. One of the input bindings is an azure cosmos db container. I have a SQL query in my function.json to already filter the result. I know a lot of the results are duplicates in the sense that they have some overlapping properties, namely companyName.
Does anyone know how to only get distinct items based on the companyName property?
I already tried the following, but they all resulted in an error.
"sqlQuery": "SELECT DISTINCT * FROM c"
"sqlQuery": "SELECT DISTINCT VALUE FROM c"
"sqlQuery": "SELECT DISTINCT * ORDER BY c.companyName FROM c"
答案1
得分: 1
"distinct"关键字在cosmos中的作用是在查询的投影中消除重复项。通过编写以下代码:
"sqlQuery": "SELECT DISTINCT c.companyName,c.nextProp,.. FROM c"
Cosmos将会输出一个新的文档(投影),其中包含您列出的所有属性都是唯一的。这是否符合您的需求?
英文:
The "distinct" key word in cosmos eliminates duplicates in the query's projection. By writing
"sqlQuery": "SELECT DISTINCT c.companyName,c.nextProp,.. FROM c"
Cosmos will output a new document (projection) based on your item where all the properties you list will be unique. Is this what you are looking for?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论