AzureFunctions.FirestoreBinding
1.0.2
.NET 5.0
This package targets .NET 5.0. The package is compatible with this framework or higher.
.NET Core 3.1
This package targets .NET Core 3.1. The package is compatible with this framework or higher.
.NET Standard 2.0
This package targets .NET Standard 2.0. The package is compatible with this framework or higher.
dotnet add package AzureFunctions.FirestoreBinding --version 1.0.2
NuGet\Install-Package AzureFunctions.FirestoreBinding -Version 1.0.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AzureFunctions.FirestoreBinding" Version="1.0.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add AzureFunctions.FirestoreBinding --version 1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: AzureFunctions.FirestoreBinding, 1.0.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install AzureFunctions.FirestoreBinding as a Cake Addin #addin nuget:?package=AzureFunctions.FirestoreBinding&version=1.0.2 // Install AzureFunctions.FirestoreBinding as a Cake Tool #tool nuget:?package=AzureFunctions.FirestoreBinding&version=1.0.2
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
AzureFunctions.FirestoreBinding
Adds support for input/output binding to your Azure functions with Firestore database.
Configuration Steps:
- Go to your firebase service account settings https://console.firebase.google.com/u/0/project/{your-project-id}/settings/serviceaccounts/adminsdk
- Create and download the private key, a JSON file will be downloaded which having all configuration to connect to firestore.
- Open the file and copy all the content inside the file.
- Now convert the JSON inside the file into Base64 Encoded format string(Tip: Use any online site/local apps if you trust those).
- The encoded string will be considered as FirebaseSecret by this library.
- Now go to your local.settings.json and inside values object configure the FireabaseSecret. The key is same i.e FirebaseSecret & value is Base64 Encoded string.
Input Binding Document, look up ID from route data:
[FunctionName("GetEmployee")]
public static IActionResult GetEmployee(
[HttpTrigger("get", Route = "GetEmployee/{empId}")] HttpRequest req,
[FirestoreDB("employees", DocId = "{empId}")] Employee employee)
{
return employee == null ? new NotFoundResult() : new OkObjectResult(employee);
}
Input Binding Document, look up ID from query string:
[FunctionName("GetEmployee")]
public static IActionResult GetEmployee(
[HttpTrigger("get", Route = "GetEmployee")] HttpRequest req,
[FirestoreDB("employees", DocId = "{Query.empId}")] Employee employee)
{
return employee == null ? new NotFoundResult() : new OkObjectResult(employee);
}
Input Binding collection:
[FunctionName("GetSeniorEmployees")]
public static async Task<IActionResult> GetSeniorEmployees(
[HttpTrigger("get", Route = "GetSeniorEmployees")] HttpRequest req,
[FirestoreDB("employees")] CollectionReference collection)
{
var employees = await collection.WhereGreaterThanOrEqualTo("Age", "40").GetDocumentsAsync<Employee>();
return new OkObjectResult(employees);
}
Output Binding single document:
[FunctionName("AddSingle")]
public static IActionResult AddSingle(
[HttpTrigger("post")] Employee employee,
[FirestoreDB("employees")] out Employee outEmployee)
{
outEmployee = employee;
return new OkObjectResult(employee);
}
Output Binding multiple document:
[FunctionName("AddBulk")]
public static async Task<IActionResult> AddBulk(
[HttpTrigger("post")] List<Employee> employees,
[FirestoreDB("employees")] IAsyncCollector<Employee> outEmployees)
{
foreach (var emp in employees)
{
await outEmployees.AddAsync(emp);
}
return new OkObjectResult("Done");
}
Extras:
For output binding documents, If you want to use Id to be consider/populated wrt to doc id in firestore then follow below approach.
[FirestoreData]
public class Employee
{
//Will use this value if assigned while doc insertion, otherwise this property will be filled with docId genereated by firestore.
//If this attribute is not there for any of property in your class, then also the output binding will work.
[FirestoreDocumentId]
public string Id { get; set; }
}
For DI of firestore into your service classes
public class EmployeeService()
{
readonly FirestoreDb _db;
public EmployeeService(FirestoreDb db)
{
_db=db;
}
public List<Employee> GetAllEmployees()
{
_db.CollectionReference("Employees").GetDocumentsAsync<Employee>();
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 is compatible. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETCoreApp 3.1
- Google.Cloud.Firestore (>= 2.4.0)
- Microsoft.Azure.WebJobs (>= 3.0.30)
-
.NETStandard 2.0
- Google.Cloud.Firestore (>= 2.4.0)
- Microsoft.Azure.WebJobs (>= 3.0.30)
-
net5.0
- Google.Cloud.Firestore (>= 2.4.0)
- Microsoft.Azure.WebJobs (>= 3.0.30)
-
net6.0
- Google.Cloud.Firestore (>= 2.4.0)
- Microsoft.Azure.WebJobs (>= 3.0.30)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.