【发布时间】:2019-09-25 00:53:36
【问题描述】:
带有 Cosmos DB + nodejs 的 Azure Function App 无法使用 SQLQuery(输入)。没有返回任何文件。
我已成功获得 Id/PartionKey 组合以返回文档。我在输入的 SQLQuery 字段中尝试了许多 SQL 查询组合,例如从文档中无济于事。没有错误也没有返回文档。我希望我的查询是:
SELECT * from Users where Users.UserName = '12345'
我尝试过在单引号中使用和不使用值。我尝试过硬编码(无绑定)查询,例如:
SELECT * from Users where Users.UserName = 12345
还有那些有绑定的(在 {userName} 周围有和没有单引号):
SELECT * from Users where Users.UserName = {userName}
我已尝试通过将 {userName} 放入路由中来使用它:
帐户/登录名/{userName}
我也尝试过使用查询中的用户名(带或不带单引号):
SELECT * from Users where Users.UserName = '{Query.userName}'
分区键是:/id
{
"indexingMode": "consistent",
"automatic": true,
"includedPaths": [
{
"path": "/*"
}
],
"excludedPaths": [
{
"path": "/\"_etag\"/?"
}
]
}
我已经进行了许多小时的搜索和阅读,我知道 SQLQuery 可能不完全支持绑定,但是,即使对值进行硬编码也无法返回文档。
示例文档:
{
"id": "e90ece01373e5d011fdaef2c20d9717b",
"UserName": "17002",
"password": "newpassword",
"Address": "123 West ",
"state": "FL",
"city": "mycity",
"zip": "32222",
"phoneNumber": "3215551212",
"emailId": "email@email.com",
"refNo": "0",
"aboutUs": "someplace",
........
}
函数.json:
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"post",
"get"
],
"route": "Account/login/{userName}"
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "cosmosDB",
"name": "myInput",
"databaseName": "cdel",
"collectionName": "Users",
"connectionStringSetting": "cdel_DOCUMENTDB",
"direction": "in",
"sqlQuery": "SELECT * FROM Users where Users.UserName = {userName}"
}
]
}
index.js:
module.exports = async function (context, req, myInput) {
context.log('JavaScript queue trigger function processed work item');
context.log('Passed in: ' + context.bindingData.userName);
if (!myInput)
{
context.log("UserName not found");
context.res = {
status: 400,
body: "UserName not found."
}
}
else
{
context.log(req.query.password);
context.log(myInput.password);
context.log(context.bindings.myInput.password);
if (myInput.password != req.query.password) {
context.res = {
status: 400,
body: "Invalid logon."
}
}
else {
.....
}
}
context.done();
};
期望返回单个文档。没有返回。 myInput.password = 未定义
是否有我没有找到的各种查询监视器,以便我可以看到正在发生的事情?
提前感谢您的帮助。
【问题讨论】:
-
这个nodejs是运行时2.0还是1.0?
-
这是在他们的门户编辑器环境中使用 nodejs。如果是 FUNCTIONS EXTENSIONS VERSION 并且基于绑定不起作用(来自我读过的许多线程),我相信它是 2.0。那说 2. 我对这个环境太陌生了。否则,我在哪里可以找到这些信息?
标签: sql node.js azure azure-cosmosdb