{"id":18075744,"url":"https://github.com/olegkorol/firestore-admin","last_synced_at":"2026-05-09T15:10:47.447Z","repository":{"id":259369147,"uuid":"877689110","full_name":"olegkorol/firestore-admin","owner":"olegkorol","description":"A simple Firestore client for Deno.","archived":false,"fork":false,"pushed_at":"2024-10-24T12:27:50.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-24T22:25:14.775Z","etag":null,"topics":["deno","firebase","firestore","firestore-admin","google-cloud","jsr"],"latest_commit_sha":null,"homepage":"https://jsr.io/@koiztech/firestore-admin","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/olegkorol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-24T04:30:12.000Z","updated_at":"2024-10-24T12:27:53.000Z","dependencies_parsed_at":"2024-10-24T22:37:04.429Z","dependency_job_id":"c5bdb8b6-aa27-4d3a-891f-ba377163a3aa","html_url":"https://github.com/olegkorol/firestore-admin","commit_stats":null,"previous_names":["olegkorol/firestore-admin"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olegkorol%2Ffirestore-admin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olegkorol%2Ffirestore-admin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olegkorol%2Ffirestore-admin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/olegkorol%2Ffirestore-admin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/olegkorol","download_url":"https://codeload.github.com/olegkorol/firestore-admin/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247393539,"owners_count":20931809,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deno","firebase","firestore","firestore-admin","google-cloud","jsr"],"created_at":"2024-10-31T11:07:08.171Z","updated_at":"2026-05-09T15:10:42.415Z","avatar_url":"https://github.com/olegkorol.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Firestore Admin Client for Deno\n\nThis is a simple Firestore Admin Client implemented for Deno. It provides an\neasy-to-use interface for interacting with Firestore databases using the Google\nCloud Firestore API.\n\n## Features\n\n- Authentication using Google Service Account\n- Automatic token refresh\n- CRUD operations on Firestore documents\n- Support for querying collections\n- Conversion between Firestore document format and JSON\n\n## Prerequisites\n\n- Deno installed on your system\n- A Google Cloud project with Firestore enabled\n- A service account JSON file with the necessary permissions\n\n## Setup\n\n1. Set the `FIREBASE_SERVICE_ACCOUNT` environment variable with the contents of\n   your service account JSON file.\n\nYou can set this environment variable in a `.env` file (do not forget to add the\n`--env` flag when running your script):\n\n```text\n# .env\n\nFIREBASE_SERVICE_ACCOUNT='{\n  \"type\": \"service_account\",\n  \"project_id\": \"XXX\",\n  \"private_key_id\": \"XXX\",\n  \"private_key\": \"XXX\",\n  \"client_email\": \"XXX@XXX.iam.gserviceaccount.com\",\n  \"client_id\": \"XXX\",\n  \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n  \"token_uri\": \"https://oauth2.googleapis.com/token\",\n  \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n  \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/XXX.iam.gserviceaccount.com\",\n  \"universe_domain\": \"googleapis.com\"\n}'\n```\n\n2. Install `@koiztech/firestore-admin` as a dependency:\n\n```bash\ndeno add jsr:@koiztech/firestore-admin\n```\n\n3. Import `FirestoreAdminClient` in your Deno script and initialise it:\n\n```typescript\nimport { FirestoreAdminClient } from \"@koiztech/firestore-admin\";\n\nconst firestore = new FirestoreAdminClient();\n```\n\n## Usage\n\n`firestore-admin` will take care of parsing the data to/from JSON when\nfetching/updating documents.\n\nIf you work with Firestore Timestamp fields, read the\n[Using timestamps](#using-timestamps) section.\u003cbr /\u003e If you need to query\ndocuments by their ID, read the [Using document IDs in a filter](#using-document-ids-in-a-filter)\nsection.\n\n### Create a document\n\n```typescript\nconst document = await firestore.createDocument(\"my-collection\", {\n  name: \"John Doe\",\n});\n\n// document = {\n//   _id: 'XXX',\n//   _path: 'my-collection/XXX',\n//   name: 'John Doe',\n// }\n```\n\nReturns the created document with an additional `_id` and `_path` fields, which\nare the document ID and path respectively.\n\n### List all documents in a collection\n\n```typescript\nconst documents = await firestore.listDocumentsInCollection(\"my-collection\");\n\n// documents = ['document1', 'document2']\n```\n\nReturns an array of document IDs.\n\n### Fetch all documents in a collection\n\nNote: The fetched documents will have an additional `_id` field, which is the\ndocument ID. `getDocumentsInCollectionGroup` additionally returns a `_path`\nproperty.\n\nTo simply fetch all documents in a collection, use `getDocumentsInCollection`,\ne.g.:\n\n```typescript\nconst collection = await firestore.getDocumentsInCollection(\"my-collection\");\n```\n\nIf you want to fetch documents from a sub collection (aka. collection group),\nyou can do so with `getDocumentsInCollectionGroup`, e.g.:\n\n```typescript\n// e.g. `my-sub-collection` is a sub collection of `my-collection/{someId}`\nconst collection = await firestore.getDocumentsInCollectionGroup(\n  \"my-sub-collection\",\n);\n```\n\n### Fetch all documents in a collection with a filter\n\nNote: The fetched documents will have an additional `_id` field, which is the\ndocument ID.\n\n\u003e You can use the same syntax for both `getDocumentsInCollection` and\n\u003e `getDocumentsInCollectionGroup` methods. The latter also returns a `_path`\n\u003e property.\n\n```typescript\n// Import the FirestoreOperator enum\nimport { FirestoreOperator } from \"@koiztech/firestore-admin\";\n\n// e.g.\nconst documents = await firestore.getDocumentsInCollection(\"my-collection\", {\n  where: {\n    filters: [\n      [\"name\", FirestoreOperator.EQUAL, \"John Doe\"],\n    ],\n  },\n});\n\n// e.g.\nconst document = await firestore.getDocument(\"my-collection\", {\n  where: {\n    filters: [\n      [\"name\", FirestoreOperator.IN, [\"John Doe\", \"Max Mustermann\"]], // example of an IN filter\n    ],\n  },\n});\n\n// e.g. a more complex query\nconst documents = await firestore.getDocumentsInCollection(\"my-collection\", {\n  where: {\n    filters: [\n      [\"name\", FirestoreOperator.EQUAL, \"Ivan Petrov\"],\n      [\"height\", FirestoreOperator.LESS_THAN, 200],\n      [\"address.city\", FirestoreOperator.EQUAL, \"Moscow\"], // example of a nested field\n      [\n        \"bornAt\",\n        FirestoreOperator.GREATER_THAN,\n        new Date(\"1990-01-01T12:50:00.000Z\"),\n      ], // example of a timestamp filter\n    ],\n  },\n  orderBy: [{ field: \"createdAt\", direction: \"DESCENDING\" }], // you can sort the results\n  limit: 3, // you can limit the number of results\n});\n```\n\n### Fetch a specific document\n\n```typescript\nconst document = await firestore.getDocument(\"my-collection/my-document\");\n```\n\n### Update a document\n\n```typescript\nawait firestore.updateDocument(\"my-collection/my-document\", {\n  name: \"John Doe\",\n});\n\n// ...or with specific update fields\n\nawait firestore.updateDocument(\"my-collection/my-document\", {\n  name: \"John Doe\",\n  age: 30, // this field will not be updated\n  address: {\n    city: \"Dubai\",\n    country: \"United Arab Emirates\", // this field will not be updated\n  },\n}, [\"name\", \"address.city\"]); // you can use nested fields as well\n```\n\nReturns the updated document with an additional `_id` and `_path` fields.\n\n## Using timestamps\n\nIf you need to use Firestore timestamps, simply use `Date` objects, e.g.:\n\n```typescript\nconst now = new Date();\n\n// ...and then use it in your document:\n\nawait firestore.createDocument(\"my-collection\", {\n  createdAt: now,\n});\n```\n\nThe above `Date` object will be converted to a Firestore timestamp\nautomatically.\n\nWhen filtering results by timestamp, make sure to use `Date` objects as well,\ne.g.:\n\n```typescript\nconst documents = await firestore.getDocumentsInCollection(\"my-collection\", {\n  where: {\n    filters: [[\n      \"createdAt\",\n      FirestoreOperator.GREATER_THAN,\n      new Date(\"2024-12-02\"),\n    ]],\n  },\n});\n```\n\nIn the query results, timestamp fields will be returned as an ISO Date string,\ne.g. `2025-01-01T00:00:00.000Z`.\n\n## Using document IDs in a filter\n\nIf you need to filter query results by document IDs in the\n`getDocumentsInCollection` method, you can do so with the `documentId` field.\n\nFor example:\n\n```typescript\n// Will return all documents in the collection with the document IDs `docId1` and `docId2`.\nconst documents = await firestore.getDocumentsInCollection(\"my-collection\", {\n  where: {\n    filters: [[\"documentId\", FirestoreOperator.IN, [\"docId1\", \"docId2\"]]],\n  },\n});\n\n// You can still combine it with other filters, e.g.:\n\nconst documents = await firestore.getDocumentsInCollection(\"my-collection\", {\n  where: {\n    filters: [\n      [\"documentId\", FirestoreOperator.IN, [\"docId1\", \"docId2\"]],\n      [\"isActive\", FirestoreOperator.EQUAL, true],\n    ],\n  },\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folegkorol%2Ffirestore-admin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Folegkorol%2Ffirestore-admin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Folegkorol%2Ffirestore-admin/lists"}