Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Tiện ích Xoá dữ liệu người dùng (delete-user-data) cho phép bạn xoá dữ liệu của người dùng khi người dùng đó bị xoá khỏi dự án Firebase của bạn. Bạn có thể định cấu hình tiện ích này để xoá dữ liệu người dùng khỏi một hoặc tất cả các dịch vụ sau: Cloud Firestore, Realtime Database hoặc Cloud Storage. Mỗi điều kiện kích hoạt của tiện ích để xoá dữ liệu đều được liên kết với UserId của người dùng.
Tiện ích này hữu ích trong việc tôn trọng quyền riêng tư của người dùng và đáp ứng các yêu cầu tuân thủ. Tuy nhiên, việc sử dụng tiện ích này không đảm bảo rằng bạn sẽ tuân thủ các quy định của chính phủ và ngành.
Trong quá trình cài đặt tiện ích, bạn sẽ được nhắc chỉ định một số tham số cấu hình:
Vị trí của Cloud Functions:
Chọn vị trí mà bạn muốn triển khai các hàm được tạo cho tiện ích này. Bạn thường muốn có một vị trí gần với cơ sở dữ liệu của mình. Để được trợ giúp chọn vị trí, hãy tham khảo hướng dẫn chọn vị trí.
Đường dẫn Cloud Firestore:
Những đường dẫn nào trong phiên bản Cloud Firestore của bạn chứa dữ liệu người dùng? Để trống nếu bạn không dùng Cloud Firestore. Nhập đường dẫn đầy đủ, phân tách bằng dấu phẩy. Bạn có thể biểu thị Mã nhận dạng người dùng của người dùng đã bị xoá bằng {UID}. Ví dụ: nếu có các bộ sưu tập users và admins, đồng thời mỗi bộ sưu tập có các tài liệu với Mã nhận dạng người dùng làm mã nhận dạng tài liệu, thì bạn có thể nhập users/{UID},admins/{UID}.
Chế độ xoá Cloud Firestore:
(Chỉ áp dụng nếu bạn sử dụng tham số Cloud Firestore paths.) Bạn muốn xoá tài liệu Cloud Firestore như thế nào? Để xoá cả các tài liệu trong các bộ sưu tập con, hãy đặt tham số này thành recursive.
Phiên bản Cơ sở dữ liệu theo thời gian thực:
Bạn muốn xoá dữ liệu người dùng khỏi phiên bản Realtime Database nào?
Vị trí của Cơ sở dữ liệu theo thời gian thực:
(Chỉ áp dụng nếu bạn cung cấp tham số Realtime Database instance.) Bạn muốn xoá dữ liệu người dùng ở vị trí nào trong Cơ sở dữ liệu theo thời gian thực?
Đường dẫn Cơ sở dữ liệu theo thời gian thực:
Những đường dẫn nào trong phiên bản Realtime Database của bạn chứa dữ liệu người dùng? Để trống nếu bạn không sử dụng Cơ sở dữ liệu theo thời gian thực. Nhập đường dẫn đầy đủ, phân tách bằng dấu phẩy. Bạn có thể biểu thị Mã nhận dạng người dùng của người dùng đã bị xoá bằng {UID}. Ví dụ: users/{UID},admins/{UID}.
Đường dẫn Cloud Storage:
Bạn lưu trữ dữ liệu người dùng ở đâu trong Google Cloud Storage? Để trống nếu bạn không sử dụng Bộ nhớ đám mây. Nhập đường dẫn đầy đủ đến các tệp hoặc thư mục trong Nhóm lưu trữ, phân tách bằng dấu phẩy. Sử dụng {UID} để biểu thị User ID của người dùng đã bị xoá và sử dụng {DEFAULT} để biểu thị Thùng lưu trữ mặc định của bạn.
Sau đây là một loạt ví dụ:
Để xoá tất cả các tệp trong nhóm mặc định của bạn bằng quy tắc đặt tên tệp {UID}-pic.png, hãy nhập {DEFAULT}/{UID}-pic.png.
Để xoá tất cả các tệp trong một nhóm khác có tên là my-app-logs theo quy tắc đặt tên tệp {UID}-logs.txt, hãy nhập {DEFAULT}/{UID}-pic.png,my-app-logs/{UID}-logs.txt.
Để cũng xoá một thư mục được gắn nhãn Mã nhận dạng người dùng và tất cả các tệp trong thư mục đó (chẳng hạn như media/{UID}), hãy nhập {DEFAULT}/{UID}-pic.png,my-app-logs/{UID}-logs.txt,{DEFAULT}/media/{UID}.
Phát hiện dữ liệu cần xoá
Tiện ích này sử dụng một số cơ chế để phát hiện dữ liệu cần xoá. Bạn phải định cấu hình rõ ràng các cơ chế này để tiện ích xoá dữ liệu. Tiện ích này sẽ chỉ xoá dữ liệu được định cấu hình rõ ràng để xoá dựa trên các cơ chế được cung cấp.
Hãy lưu ý những điểm khác biệt sau đây về hành vi giữa mỗi dịch vụ:
Cloud Firestore: hành vi mặc định là xoá nông một tài liệu (các bộ sưu tập con sẽ không bị xoá). Để xoá đệ quy tất cả các bộ sưu tập con của một tài liệu, hãy đặt lựa chọn "Chế độ xoá Cloud Firestore" thành "Đệ quy".
Realtime Database: tất cả dữ liệu tại nút được chỉ định sẽ bị xoá.
Bộ nhớ: nếu bạn chỉ định một đường dẫn thư mục, thì tất cả các tệp và thư mục con sẽ bị xoá.
Theo đường dẫn
Khi định cấu hình các đường dẫn Cloud Firestore, Realtime Database và Cloud Storage, bạn có thể xác định một biến UID trong các đường dẫn sẽ được thay thế bằng UID của người dùng đã xác thực. Khi một người dùng bị xoá, tiện ích sẽ xoá tất cả dữ liệu được khoá bằng UID đó tại các đường dẫn đã cho, ví dụ:
Đường dẫn Cloud Firestore: users/{UID},admins/{UID}
Đường dẫn đến Cơ sở dữ liệu theo thời gian thực: likes/{UID}
Đường dẫn đến Cloud Storage: {DEFAULT}/uploads/{UID},{DEFAULT}/avatars/{UID}.jpeg
Tự động phát hiện (Cloud Firestore)
Để cho phép tiện ích tự động phát hiện các tài liệu Firestore cần xoá, hãy đặt thông số cấu hình "Bật tính năng tự động phát hiện" thành "Có".
Tính năng tự động phát hiện hoạt động bằng cách tự động duyệt qua cơ sở dữ liệu để tìm các bộ sưu tập và tài liệu cần xoá theo cấu hình của bạn. Tiện ích xác định những bộ sưu tập và tài liệu đó bằng phương pháp sau:
Trước tiên, tiện ích sẽ tìm tất cả các tập hợp gốc trong cơ sở dữ liệu. Nếu mã nhận dạng của một bộ sưu tập khớp với mã nhận dạng người dùng (UID), thì toàn bộ bộ sưu tập sẽ bị xoá (việc xoá là đệ quy hoặc nông, tuỳ thuộc vào cấu hình của tiện ích cho "Chế độ xoá Cloud Firestore").
Thứ hai, nếu mã nhận dạng bộ sưu tập không khớp, tiện ích sẽ cố gắng xác định và xoá một tài liệu nếu mã nhận dạng tài liệu của tài liệu đó khớp với mã nhận dạng người dùng (UID) của người dùng.
Cuối cùng, đối với mỗi tài liệu:
a. Nếu độ sâu tìm kiếm hiện tại (xem bên dưới) nhỏ hơn hoặc bằng độ sâu tìm kiếm đã định cấu hình, thì quy trình này sẽ được lặp lại cho tất cả các bộ sưu tập con của tài liệu hiện tại.
b. Nếu bạn đã định cấu hình các trường tìm kiếm, thì tiện ích sẽ kiểm tra xem các trường được cung cấp có khớp với UID của người dùng hay không. Nếu tìm thấy nội dung trùng khớp, tài liệu sẽ bị xoá.
Số trang trung bình được xem sau mỗi tìm kiếm
Tiện ích này cung cấp một giá trị độ sâu tìm kiếm có thể định cấu hình (mặc định là 3). Quá trình duyệt qua sẽ chỉ được thực thi nếu độ sâu tìm kiếm hiện tại nhỏ hơn hoặc bằng độ sâu tìm kiếm đã định cấu hình. Độ sâu tìm kiếm hiện tại dựa trên độ sâu của bộ sưu tập hiện tại hoặc bộ sưu tập mẹ của tài liệu, ví dụ:
Tiện ích này sẽ KHÔNG tự động xoá UID được lưu trữ trong các mảng hoặc bản đồ, đồng thời sẽ không tìm kiếm dữ liệu được khoá bằng mã nhận dạng người dùng được lưu trữ trong các bộ sưu tập con lồng nhau sâu quá độ sâu được chỉ định ở trên.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-25 UTC."],[],[],null,["\u003cbr /\u003e\n\nThe Delete User Data extension (`delete-user-data`) lets you delete a user's data when the user is deleted from your Firebase project. You can configure this extension to delete user data from any or all of the following: Cloud Firestore, Realtime Database, or Cloud Storage. Each trigger of the extension to delete data is keyed to the user's `UserId`.\n| **Note:** To use this extension, you need to manage your users with Firebase Authentication.\n\nThis extension is useful for respecting user privacy and fulfilling compliance requirements. However, using this extension does not guarantee compliance with government and industry regulations.\n\nPrerequisites\n\n- You must use [Firebase Authentication](https://firebase.google.com/docs/auth) to manage your users.\n\n- This extension only deletes data from [Cloud Firestore](https://firebase.google.com/docs/firestore), [Realtime Database](https://firebase.google.com/docs/database), and [Cloud Storage](https://firebase.google.com/docs/storage). If you store user data elsewhere, you should also delete user data from those sources when you delete users.\n\nInstall the extension\n\nTo install the extension, follow the steps on the [Install Firebase Extension](https://firebase.google.com/docs/extensions/install-extensions) page. In summary, do one of the following:\n\n- **Firebase console:** Click the following button:\n\n [Install the Delete User Data extension](https://console.firebase.google.com/project/_/extensions/install?ref=firebase%2Fdelete-user-data)\n- **CLI:** Run the following command:\n\n firebase ext:install firebase/delete-user-data --project=\u003cvar translate=\"no\"\u003eprojectId-or-alias\u003c/var\u003e\n\nDuring the installation of the extension, you will be prompted to specify a number of configuration parameters:\n\n- **Cloud Functions location:**\n\n Select the location of where you want to deploy the functions created for this extension. You usually want a location close to your database. For help selecting a location, refer to the [location selection guide](https://firebase.google.com/docs/functions/locations).\n- **Cloud Firestore paths:**\n\n Which paths in your Cloud Firestore instance contain user data? Leave empty if you don't use Cloud Firestore. Enter the full paths, separated by commas. You can represent the User ID of the deleted user with `{UID}`. For example, if you have the collections `users` and `admins`, and each collection has documents with the User ID as document IDs, then you can enter `users/{UID},admins/{UID}`.\n- **Cloud Firestore delete mode:**\n\n (Only applicable if you use the `Cloud Firestore paths` parameter.) How do you want to delete Cloud Firestore documents? To also delete documents in subcollections, set this parameter to `recursive`.\n- **Realtime Database instance:**\n\n From which Realtime Database instance do you want to delete user data?\n- **Realtime Database location:**\n\n (Only applicable if you provided the `Realtime Database instance` parameter.) From which Realtime Database location do you want to delete user data?\n- **Realtime Database paths:**\n\n Which paths in your Realtime Database instance contain user data? Leave empty if you don't use Realtime Database. Enter the full paths, separated by commas. You can represent the User ID of the deleted user with `{UID}`. For example: `users/{UID},admins/{UID}`.\n- **Cloud Storage paths:**\n\n Where in Google Cloud Storage do you store user data? Leave empty if you don't use Cloud Storage. Enter the full paths to files or directories in your Storage buckets, separated by commas. Use `{UID}` to represent the User ID of the deleted user, and use `{DEFAULT}` to represent your default Storage bucket.\n\n Here's a series of examples:\n - To delete all the files in your default bucket with the file naming scheme `{UID}-pic.png`, enter `{DEFAULT}/{UID}-pic.png`.\n - To also delete all the files in another bucket called `my-app-logs` with the file naming scheme `{UID}-logs.txt`, enter `{DEFAULT}/{UID}-pic.png,my-app-logs/{UID}-logs.txt`.\n - To *also* delete a User ID-labeled directory and all its files (like `media/{UID}`), enter `{DEFAULT}/{UID}-pic.png,my-app-logs/{UID}-logs.txt,{DEFAULT}/media/{UID}`.\n\nDiscovering data for deletion\n\nThere are a few mechanisms that this extension uses to discover data for deletion. These mechanisms have to be explicitly configured for the extension to delete data. The extension will only delete data that is explicitly configured to delete based on the mechanisms provided.\n\nBe aware of the following behavioral differences between each service:\n\n- Cloud Firestore: the default behavior is to shallow delete a document (sub-collections will not be deleted). To recursively delete all sub-collections of a document, set the \"Cloud Firestore delete mode\" option to \"Recursive\".\n- Realtime Database: all data at the specified node will be deleted.\n- Storage: if a directory path is specified, all files and sub-directories will be deleted.\n\nBy path\n\nWhen configuring the Cloud Firestore, Realtime Database \\& Cloud Storage paths, it's possible to define a `UID` variable in the paths which will be replaced with the authenticated user's UID. When a user is deleted, the extension will delete all data keyed on that UID at the given paths, for example:\n\n- Cloud Firestore path(s): `users/{UID},admins/{UID}`\n- Realtime Database path(s): `likes/{UID}`\n- Cloud Storage path(s): `{DEFAULT}/uploads/{UID},{DEFAULT}/avatars/{UID}.jpeg`\n\nAuto Discovery (Cloud Firestore)\n\nTo enable the extension to automatically discover Firestore documents to delete, set the \"Enable auto discovery\" configuration parameter to \"Yes\".\n\nAuto-discovery works by automatically traversing the database to find collections and documents which should be deleted according to your configuration. The extension identifies those collections and documents with the following methodology:\n\n1. First, the extension finds all root collections in the database. If a collection's ID matches that of the user's UID, the entire collection is deleted (deletion is either recursive or shallow, depending on the extensions's configuration for \"Cloud Firestore delete mode\").\n2. Secondly, if the collection ID does not match, the extension will attempt to identify and delete a document if its document ID matches that of the user's UID.\n3. Finally, for each document: a. If the current search depth (see below) is less than or equal to the configured search depth, the process will be repeated for all of the current document's sub-collections. b. If search fields have been configured, the extension will check if the provided fields match the user's UID. If a match is found, the document will be deleted.\n\nSearch Depth\n\nThe extension offers a configurable search depth value (defaulting to 3). Traversal will only be executed if the current search depth is less than or equal to the configured search depth. The current search depth is based on the depth of the current collection or documents parent collection, for example \n\n /users = 1\n /users/\u003cdocument-id\u003e = 1\n /users/\u003cdocument-id\u003e/comments = 2\n /users/\u003cdocument-id\u003e/comments/\u003cdocument-id\u003e = 2\n\nThis extension will NOT automatically delete UIDs stored in arrays or maps, and it will not search for data keyed by user ID stored in deeply nested subcollections past the depth specified above.\n| **Note:** with large databases, traversal-based discovery may incur many reads and deletions since it reads all documents in the corresponding collections. Please be aware of Cloud Firestore billing prices and how this might impact you. Auto discovery is completely optional."]]