const { app, input } = require('@azure/functions');
const cosmosInput = input.cosmosDB({
databaseName: 'rcmapp',
collectionName: 'users',
id: '{request.user.id}',
partitionKey: '{request.user.id}',
connectionStringSetting: 'COSMOS_CONNECTION_STRING'
});
app.http('userDetails', {
methods: ['GET'],
authLevel: 'anonymous',
extraInputs: [cosmosInput],
handler: (request, context) => {
context.log(`User details function triggered`);
const userDetails = JSON.parse(context.extraInputs.get(cosmosInput));
return {
body: userDetails
};
}
});
有没有办法可以使用绑定表达式访问此值以传递到输入绑定?
通过将 user_Id作为参数传递给Http请求来获取用户详细信息。
const { app, input } = require('@azure/functions');
const cosmosInput = input.cosmosDB({
databaseName: 'userdetails',
containerName: 'usercontainer',
id: '{Query.id}',
partitionKey: '{Query.user_id}',
connection: 'cosmosconnection'
});
app.http('userDetails', {
methods: ['GET','POST'],
authLevel: 'anonymous',
extraInputs: [cosmosInput],
handler: (request, context) => {
context.log(`User details function triggered`);
const userDetails = context.extraInputs.get(cosmosInput);
return {
body: `Found user details with id ${userDetails.user_name}`,
};
}
});
/user_id
作为分区键。
在本地运行该函数: