إزالة الحقول

الوصف

إزالة الحقول من المستندات التي تم إنتاجها في المرحلة السابقة

ستحتوي المستندات التي تم إنشاؤها على جميع الحقول من المرحلة السابقة باستثناء الحقول المحدّدة التي ستتم إزالتها.

أمثلة

Node.js
const results = await db.pipeline()
  .collection("cities")
  .removeFields("population", "location.state")
  .execute();

Web

const results = await execute(db.pipeline()
  .collection("cities")
  .removeFields("population", "location.state"));
Swift
let results = try await db.pipeline()
  .collection("cities")
  .removeFields(["population", "location.state"])
  .execute()

Kotlin

val results = db.pipeline()
    .collection("cities")
    .removeFields("population", "location.state")
    .execute()

Java

Task<Pipeline.Snapshot> results = db.pipeline()
        .collection("cities")
        .removeFields("population", "location.state")
        .execute();
Python
results = (
    client.pipeline()
    .collection("cities")
    .remove_fields("population", "location.state")
    .execute()
)
Java
Pipeline.Snapshot results =
    firestore
        .pipeline()
        .collection("cities")
        .removeFields("population", "location.state")
        .execute()
        .get();

السلوك

إزالة الحقول المتداخلة

تلتزم المرحلة remove_fields(...) ببنية الحقول المتداخلة، وستزيل المفاتيح من الخريطة.

على سبيل المثال، لإزالة حقل الولاية المتداخل من مجموعة البيانات، اتّبِع الخطوات التالية:

Node.js

await db.collection("cities").doc("SF").set({name: "San Francisco", location: {country: "USA", state: "California"}});
await db.collection("cities").doc("TO").set({name: "Toronto", location: {country: "Canada", province: "Ontario"}});

يمكن استخدام مسار المعالجة التالي:

Node.js

const results = await db.pipeline()
  .collection("/cities")
  .removeFields("location.state")
  .execute();

التي تنتج المستندات التالية:

{ name: "San Francisco", location: { country: "USA" } }
{ name: "Toronto", location: { country: "Canada", province: "Ontario" } }

لا تتوفّر إمكانية إزالة عناصر من داخل صفيف.

الإزالة عند عدم توفّر الحقول

إذا لم يكن الحقل المتداخل أو الحقل ذو المستوى الأعلى الذي تم تقديمه إلى remove_fields(...) متوفّرًا في مستند، لن تعدّل المرحلة المستند لهذا الحقل. وستستمر إزالة الحقول الأخرى الحالية.