如何在 Cosmos DB 中检索具有所有属性的不同项?

huangapple go评论51阅读模式
英文:

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?

huangapple
  • 本文由 发表于 2023年7月14日 02:21:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/76682256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定