在 Azure Cosmos DB 中指定别名Aliasing in Azure Cosmos DB

可以显式为查询中的值指定别名。You can explicitly alias values in queries. 如果查询包含两个同名的属性,请使用别名来重命名其中一个或两个属性,以便可以在投影的结果中消除其歧义。If a query has two properties with the same name, use aliasing to rename one or both of the properties so they're disambiguated in the projected result.

示例Examples

如以下示例所示,将第二个值投影为 NameInfo 时,用于别名的 AS 关键字是可选的:The AS keyword used for aliasing is optional, as shown in the following example when projecting the second value as NameInfo:

    SELECT 
           { "state": f.address.state, "city": f.address.city } AS AddressInfo,
           { "name": f.id } NameInfo
    FROM Families f
    WHERE f.id = "AndersenFamily"

结果有:The results are:

    [{
      "AddressInfo": {
        "state": "WA",
        "city": "Seattle"
      },
      "NameInfo": {
        "name": "AndersenFamily"
      }
    }]

后续步骤Next steps