我有一个Azure函数,该函数正在查询肯定包含数据的cosmos db mongo集合。
但是,当通过我的azure函数查询时,该函数返回一个空数组。
我的功能类似于:
[FunctionName("GetAll")]
public static IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]HttpRequest req,
TraceWriter log, [Inject(typeof(IWarehouseStateRepository))]IWarehouseStateRepository repoW)
{
log.Info("GetAll Function is processing a request");
var warehouses = repoW.GetAllWarehouses();
return warehouses != null ?
(ActionResult)new OkObjectResult(warehouses) :
new BadRequestObjectResult("Something went wrong with this request");
}
我正在为我的仓库存储库注入自定义类型,该类型取决于数据库配置上下文,如下所示:
public class StateContext : IStateContext
{
private readonly IMongoDatabase _database = null;
private readonly string _connectionString;
private readonly string _dbName;
private readonly string _collectionName;
public StateContext()
{
_connectionString = Environment.GetEnvironmentVariable("AggregateDbConnectionDev");
_dbName = Environment.GetEnvironmentVariable("AggregateDbNameDev");
_collectionName = Environment.GetEnvironmentVariable("AggregateDbCollectionDev");
MongoClientSettings settings = MongoClientSettings.FromUrl(new MongoUrl(_connectionString));
settings.SslSettings = new SslSettings() { EnabledSslProtocols = SslProtocols.Tls12 };
var client = new MongoClient(settings);
if (client != null)
_database = client.GetDatabase(_dbName);
}
public IMongoCollection<WarehouseState> WarehouseState
{
get
{
return _database.GetCollection<WarehouseState>(_collectionName);
}
}
}
该函数不引发任何错误或异常。
回购查询:
public IEnumerable<WarehouseState> GetAllWarehouses()
{
var warehouses = _context.WarehouseState.Find(_ => true).ToList();
return warehouses;
}
有没有人知道这里可能出什么问题?我是否需要使用天蓝色功能以其他方式设置cosmos Db连接?
在将逻辑移到天蓝色函数之前,此设置以前已经起作用。