নিম্নলিখিত উদাহরণগুলি প্রদর্শন করে যে কীভাবে নথি, ক্ষেত্র এবং সংগ্রহগুলি মুছতে হয়।
নথি মুছুন
একটি নথি মুছে ফেলতে, delete()
পদ্ধতি ব্যবহার করুন:
Web version 9
import { doc, deleteDoc } from "firebase/firestore"; await deleteDoc(doc(db, "cities", "DC"));
Web version 8
db.collection("cities").doc("DC").delete().then(() => { console.log("Document successfully deleted!"); }).catch((error) => { console.error("Error removing document: ", error); });
সুইফট
db.collection("cities").document("DC").delete() { err in if let err = err { print("Error removing document: \(err)") } else { print("Document successfully removed!") } }
উদ্দেশ্য গ
[[[self.db collectionWithPath:@"cities"] documentWithPath:@"DC"] deleteDocumentWithCompletion:^(NSError * _Nullable error) { if (error != nil) { NSLog(@"Error removing document: %@", error); } else { NSLog(@"Document successfully removed!"); } }];
Java
db.collection("cities").document("DC") .delete() .addOnSuccessListener(new OnSuccessListener<Void>() { @Override public void onSuccess(Void aVoid) { Log.d(TAG, "DocumentSnapshot successfully deleted!"); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Error deleting document", e); } });
Kotlin+KTX
db.collection("cities").document("DC") .delete() .addOnSuccessListener { Log.d(TAG, "DocumentSnapshot successfully deleted!") } .addOnFailureListener { e -> Log.w(TAG, "Error deleting document", e) }
Dart
db.collection("cities").doc("DC").delete().then( (doc) => print("Document deleted"), onError: (e) => print("Error updating document $e"), );
জাভা
পাইথন
Python
সি++
db->Collection("cities").Document("DC").Delete().OnCompletion( [](const Future<void>& future) { if (future.error() == Error::kErrorOk) { std::cout << "DocumentSnapshot successfully deleted!" << std::endl; } else { std::cout << "Error deleting document: " << future.error_message() << std::endl; } });
Node.js
যাওয়া
পিএইচপি
$db->collection('samples/php/cities')->document('DC')->delete();
ঐক্য
DocumentReference cityRef = db.Collection("cities").Document("DC"); cityRef.DeleteAsync();
সি#
DocumentReference cityRef = db.Collection("cities").Document("DC"); await cityRef.DeleteAsync();
রুবি
আপনি যখন একটি নথি মুছে দেন, তখন ক্লাউড ফায়ারস্টোর স্বয়ংক্রিয়ভাবে তার উপ-সংগ্রহের মধ্যে থাকা দস্তাবেজগুলি মুছে দেয় না। আপনি এখনও রেফারেন্স দ্বারা উপসংগ্রহ নথি অ্যাক্সেস করতে পারেন. উদাহরণ স্বরূপ, আপনি path /mycoll/mydoc/mysubcoll/mysubdoc
এ ডকুমেন্টটি অ্যাক্সেস করতে পারবেন এমনকি যদি আপনি /mycoll/mydoc
এ পূর্বপুরুষ নথিটি মুছে দেন।
অস্তিত্বহীন পূর্বপুরুষের নথিগুলি কনসোলে উপস্থিত হয় , কিন্তু সেগুলি ক্যোয়ারী ফলাফল এবং স্ন্যাপশটে উপস্থিত হয় না৷
আপনি যদি একটি নথি এবং তার উপ-সংগ্রহের মধ্যে থাকা সমস্ত নথি মুছতে চান, তাহলে আপনাকে অবশ্যই তা ম্যানুয়ালি করতে হবে। আরও তথ্যের জন্য, সংগ্রহগুলি মুছুন দেখুন।
ক্ষেত্রগুলি মুছুন
একটি নথি থেকে নির্দিষ্ট ক্ষেত্র মুছে ফেলার জন্য, আপনি একটি নথি আপডেট করার সময় FieldValue.delete()
পদ্ধতি ব্যবহার করুন:
Web version 9
import { doc, updateDoc, deleteField } from "firebase/firestore"; const cityRef = doc(db, 'cities', 'BJ'); // Remove the 'capital' field from the document await updateDoc(cityRef, { capital: deleteField() });
Web version 8
var cityRef = db.collection('cities').doc('BJ'); // Remove the 'capital' field from the document var removeCapital = cityRef.update({ capital: firebase.firestore.FieldValue.delete() });
সুইফট
db.collection("cities").document("BJ").updateData([ "capital": FieldValue.delete(), ]) { err in if let err = err { print("Error updating document: \(err)") } else { print("Document successfully updated") } }
উদ্দেশ্য গ
[[[self.db collectionWithPath:@"cities"] documentWithPath:@"BJ"] updateData:@{ @"capital": [FIRFieldValue fieldValueForDelete] } completion:^(NSError * _Nullable error) { if (error != nil) { NSLog(@"Error updating document: %@", error); } else { NSLog(@"Document successfully updated"); } }];
Java
DocumentReference docRef = db.collection("cities").document("BJ"); // Remove the 'capital' field from the document Map<String,Object> updates = new HashMap<>(); updates.put("capital", FieldValue.delete()); docRef.update(updates).addOnCompleteListener(new OnCompleteListener<Void>() { // ... // ...
Kotlin+KTX
val docRef = db.collection("cities").document("BJ") // Remove the 'capital' field from the document val updates = hashMapOf<String, Any>( "capital" to FieldValue.delete() ) docRef.update(updates).addOnCompleteListener { }
Dart
final docRef = db.collection("cities").doc("BJ"); // Remove the 'capital' field from the document final updates = <String, dynamic>{ "capital": FieldValue.delete(), }; docRef.update(updates);
জাভা
পাইথন
Python
সি++
DocumentReference doc_ref = db->Collection("cities").Document("BJ"); doc_ref.Update({{"capital", FieldValue::Delete()}}) .OnCompletion([](const Future<void>& future) { /*...*/ });
Node.js
যাওয়া
পিএইচপি
$cityRef = $db->collection('samples/php/cities')->document('BJ'); $cityRef->update([ ['path' => 'capital', 'value' => FieldValue::deleteField()] ]);
ঐক্য
DocumentReference cityRef = db.Collection("cities").Document("BJ"); Dictionary<string, object> updates = new Dictionary<string, object> { { "Capital", FieldValue.Delete } };
সি#
DocumentReference cityRef = db.Collection("cities").Document("BJ"); Dictionary<string, object> updates = new Dictionary<string, object> { { "Capital", FieldValue.Delete } }; await cityRef.UpdateAsync(updates);
রুবি
সংগ্রহগুলি মুছুন
ক্লাউড ফায়ারস্টোরে একটি সম্পূর্ণ সংগ্রহ বা উপ-সংগ্রহ মুছে ফেলতে, সংগ্রহ বা উপ-সংগ্রহের মধ্যে থাকা সমস্ত নথি পুনরুদ্ধার করুন এবং সেগুলি মুছুন। আপনার যদি বড় সংগ্রহ থাকে, তাহলে মেমরির বাইরের ত্রুটিগুলি এড়াতে আপনি ছোট ব্যাচে নথিগুলি মুছতে চাইতে পারেন। যতক্ষণ না আপনি সম্পূর্ণ সংগ্রহ বা উপসংগ্রহটি মুছে ফেলছেন ততক্ষণ প্রক্রিয়াটি পুনরাবৃত্তি করুন।
একটি সংগ্রহ মুছে ফেলার জন্য একটি সীমাহীন সংখ্যক পৃথক মুছে ফেলার অনুরোধগুলির সমন্বয় প্রয়োজন। আপনি যদি সম্পূর্ণ সংগ্রহগুলি মুছে ফেলতে চান তবে এটি শুধুমাত্র একটি বিশ্বস্ত সার্ভার পরিবেশ থেকে করুন৷ যদিও মোবাইল/ওয়েব ক্লায়েন্ট থেকে একটি সংগ্রহ মুছে ফেলা সম্ভব, এটি করার নেতিবাচক নিরাপত্তা এবং কর্মক্ষমতা প্রভাব আছে।
নীচের স্নিপেটগুলি কিছুটা সরলীকৃত এবং ত্রুটি হ্যান্ডলিং, নিরাপত্তা, উপ-সংগ্রহগুলি মুছে ফেলা বা কর্মক্ষমতা সর্বাধিক করার সাথে কাজ করে না। উত্পাদনে সংগ্রহগুলি মুছে ফেলার জন্য একটি প্রস্তাবিত পদ্ধতি সম্পর্কে আরও জানতে, সংগ্রহ এবং উপ-সংগ্রহগুলি মুছে ফেলা দেখুন।
ওয়েব
// Deleting collections from a Web client is not recommended.
সুইফট
// Deleting collections from an Apple client is not recommended.
উদ্দেশ্য গ
// Deleting collections from an Apple client is not recommended.
Java
// Deleting collections from an Android client is not recommended.
Kotlin+KTX
// Deleting collections from an Android client is not recommended.
Dart
ক্লায়েন্ট থেকে সংগ্রহ মুছে ফেলার সুপারিশ করা হয় না.
জাভা
পাইথন
Python
সি++
// This is not supported. Delete data using CLI as discussed below.
Node.js
যাওয়া
পিএইচপি
function data_delete_collection(string $projectId, string $collectionName, int $batchSize) { // Create the Cloud Firestore client $db = new FirestoreClient([ 'projectId' => $projectId, ]); $collectionReference = $db->collection($collectionName); $documents = $collectionReference->limit($batchSize)->documents(); while (!$documents->isEmpty()) { foreach ($documents as $document) { printf('Deleting document %s' . PHP_EOL, $document->id()); $document->reference()->delete(); } $documents = $collectionReference->limit($batchSize)->documents(); } }
ঐক্য
// This is not supported. Delete data using CLI as discussed below.
সি#
private static async Task DeleteCollection(CollectionReference collectionReference, int batchSize) { QuerySnapshot snapshot = await collectionReference.Limit(batchSize).GetSnapshotAsync(); IReadOnlyList<DocumentSnapshot> documents = snapshot.Documents; while (documents.Count > 0) { foreach (DocumentSnapshot document in documents) { Console.WriteLine("Deleting document {0}", document.Id); await document.Reference.DeleteAsync(); } snapshot = await collectionReference.Limit(batchSize).GetSnapshotAsync(); documents = snapshot.Documents; } Console.WriteLine("Finished deleting all documents from the collection."); }
রুবি
Firebase CLI দিয়ে ডেটা মুছুন
দস্তাবেজ এবং সংগ্রহগুলি মুছতে আপনি Firebase CLI ব্যবহার করতে পারেন। তথ্য মুছে ফেলার জন্য নিম্নলিখিত কমান্ড ব্যবহার করুন:
firebase firestore:delete [options] <<path>>
কনসোল দিয়ে ডেটা মুছুন
আপনি কনসোলে ক্লাউড ফায়ারস্টোর পৃষ্ঠা থেকে নথি এবং সংগ্রহগুলি মুছতে পারেন। কনসোল থেকে একটি নথি মুছে ফেললে সেই নথিতে থাকা সমস্ত নেস্টেড ডেটা মুছে যায়, যেকোন উপ-সংগ্রহ সহ।