在 Azure 函数和 Cosmos DB 中使用查询参数
Using query params in Azure functions and Cosmos DB
我正在使用 Azure Functions 从 Cosmos DB 检索数据。不,我有以下 SQL 查询:
SELECT * FROM r WHERE r.city = {city} AND r.district = {district} AND r.max_number_of_people = {people}
当我使用这些作为查询参数发出请求时:“?city=Amsterdam&district=West&people=2” 我没有得到任何回复。我在没有 people 参数的情况下尝试过,然后就可以了。
我认为这与 max_number_of_people 在我的容器中保存为数字有关,但我不确定。
这可能是什么问题?
// function.json
{
"bindings": [
{
"name": "req",
"route": "restaurants/available",
"authLevel": "function",
"methods": ["get"],
"direction": "in",
"type": "httpTrigger"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "restaurants",
"databaseName": "find-your-spot",
"collectionName": "restaurants",
"connectionStringSetting": "fys-d-cdb_DOCUMENTDB",
"sqlQuery": "SELECT * FROM r WHERE r.city = {city} AND r.district = {district} AND r.max_number_of_people = {people}",
"direction": "in",
"type": "cosmosDB"
}
]
}
// index.js
module.exports = async function (context, req, restaurants) {
try {
context.res.status(200).json(restaurants);
} catch (error) {
context.res.status(500).json(error);
}
};
嗯,我找到了一种方法来完成我想要的。这可能不是唯一的方法。
SELECT * FROM r WHERE r.city = {city} AND r.district = {district} AND ToString(r.max_number_of_people) = {people}
我正在使用 Azure Functions 从 Cosmos DB 检索数据。不,我有以下 SQL 查询:
SELECT * FROM r WHERE r.city = {city} AND r.district = {district} AND r.max_number_of_people = {people}
当我使用这些作为查询参数发出请求时:“?city=Amsterdam&district=West&people=2” 我没有得到任何回复。我在没有 people 参数的情况下尝试过,然后就可以了。
我认为这与 max_number_of_people 在我的容器中保存为数字有关,但我不确定。
这可能是什么问题?
// function.json
{
"bindings": [
{
"name": "req",
"route": "restaurants/available",
"authLevel": "function",
"methods": ["get"],
"direction": "in",
"type": "httpTrigger"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"name": "restaurants",
"databaseName": "find-your-spot",
"collectionName": "restaurants",
"connectionStringSetting": "fys-d-cdb_DOCUMENTDB",
"sqlQuery": "SELECT * FROM r WHERE r.city = {city} AND r.district = {district} AND r.max_number_of_people = {people}",
"direction": "in",
"type": "cosmosDB"
}
]
}
// index.js
module.exports = async function (context, req, restaurants) {
try {
context.res.status(200).json(restaurants);
} catch (error) {
context.res.status(500).json(error);
}
};
嗯,我找到了一种方法来完成我想要的。这可能不是唯一的方法。
SELECT * FROM r WHERE r.city = {city} AND r.district = {district} AND ToString(r.max_number_of_people) = {people}