【问题标题】:How Execute SQL Query in Azure Cosmos DB with Node.js如何使用 Node.js 在 Azure Cosmos DB 中执行 SQL 查询
【发布时间】:2020-03-17 17:55:16
【问题描述】:

我正在使用以下文档向我展示如何使用 Node.JS 从 Azure Cosmos DB SQL API 帐户连接和查询数据

https://docs.microsoft.com/en-us/azure/cosmos-db/create-sql-api-nodejs

文档中有一个部分设置为查询 Azure Cosmos DB

// query to return all items
const querySpec = {
  query: "SELECT * from c"
};

const { resources: results } = await container.items
  .query(querySpec)
  .fetchAll();

有人可以告诉我上述查询的结果显示在哪里吗?

我正在使用 Visual Studio Code 来构建代码,但是当我运行它时,我不确定结果会显示在哪里。例如,结果是否会显示在 Azure Cosmos DB 中?在 Visual Studio 代码中?还是在哪里?

你可能已经知道我是 Node.JS 新手

谢谢

【问题讨论】:

    标签: node.js azure-cosmosdb


    【解决方案1】:

    默认情况下,它将显示在您运行代码的控制台中。但是我在您的代码中没有看到任何输出,也许您应该添加如下内容

      if (results.length == 0) {
        throw "No items found matching";
      } 
    
      // Change person to your data type
      const person = results[0];
      console.log("The '" + person.id + "' family has lastName '" + person.lastName + "'");
      console.log("The '" + person.id + "' family has " + person.children.length + " children '");
    

    【讨论】:

    • 感谢您与我们联系。我不明白你的建议。如果您转到我提供的链接,您将看到我正在使用的完整代码。
    猜你喜欢
    • 1970-01-01
    • 2021-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多