简体   繁体   中英

How Execute SQL Query in Azure Cosmos DB with Node.js

I'm using the following document to show me how to connect and query data from Azure Cosmos DB SQL API account using Node.JS

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

There is a section in the document that is set to query the Azure Cosmos DB

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

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

Can someone let me know where the results of the above query is displayed?

I'm using Visual Studio Code to build the code, but when I run it I'm not sure where the results are displayed. For example, will the results be display in Azure Cosmos DB? Within Visual Studio Code? or where?

You've probably gathered I'm a Node.JS newbie

Thanks

By default, it will show in your console where you run your code. But I did not see any output in your code, maybe you should add something like the following

  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 '");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM