public void ValidateQueryConfiguration(QueryConfig queryConfig) { _dbService.Init(queryConfig.DbSettings); var isExisted = _dbService.CollectionExists(queryConfig.DbSettings.Entity); if (!isExisted) { _logger.LogError($"Collection {queryConfig.DbSettings.Entity} doesn't exist"); throw new ArgumentException($"Collection {queryConfig.DbSettings.Entity} doesn't exist"); } var singleDoc = _dbService.GetOneDocument(queryConfig.DbSettings.Entity); if (!ValidateOutputMapping(singleDoc, queryConfig.Mappings)) { _logger.LogError($"Output mapping of {queryConfig.Name} has invalid column"); throw new ArgumentException($"Output mapping of {queryConfig.Name} has invalid column"); } if (!ValidateQueryField(singleDoc, queryConfig.QueryField)) { _logger.LogError($"Query Field of {queryConfig.Name} doesn't match with any document fields"); throw new ArgumentException( $"Query Field of {queryConfig.Name} doesn't match with any document fields"); } }
public Task <ResponseMsg <JObject> > Handle(MongodbSourceRequest request, CancellationToken cancellationToken) { var output = new ResponseMsg <JObject>(); _logger.LogInformation("Start querying from Mongodb source..", request); _service.Init(request.ReqMsg.QueriedInstance.DbSettings); var queriedResult = _service.QueryTextWithMapping(request.ReqMsg.QueriedInstance.QueryField, request.ReqMsg.QueriedText, request.ReqMsg.Limit, request.ReqMsg.Skip, request.ReqMsg.QueriedInstance.Mappings, _mapping); output.Results = queriedResult; output.Skip = request.ReqMsg.Skip; output.Limit = request.ReqMsg.Limit; return(Task.FromResult(output)); }