Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.

Paste

Pasted as Objective C by brian ( 5 years ago )
- (void)testBatchDelete {
  FIRCollectionReference *coll = [self.db collectionWithPath:@"aaa"];
  [[coll queryWhereField:@"value"
               isEqualTo:@"foo"] addSnapshotListener:^(FIRQuerySnapshot *snap, NSError *error) {
    printf("--------------------snapshot size: %lu\n",
           (unsigned long)[[snap documentChanges] count]);
    XCTAssertNil(error);
  }];
 
  FIRDocumentReference *doc1 = [coll documentWithAutoID];
  FIRDocumentReference *doc2 = [coll documentWithAutoID];
  FIRDocumentReference *doc3 = [coll documentWithAutoID];
  NSDictionary<NSString *, id> *data = @{@"value" : @"foo"};
 
  // Write to documents.
  XCTestExpectation *batchExpectation = [self expectationWithDescription:@"batch written"];
  FIRWriteBatch *batch = [doc1.firestore batch];
  [batch setData:data forDocument:doc1];
  [batch setData:data forDocument:doc2];
  [batch setData:data forDocument:doc3];
  [batch commitWithCompletion:^(NSError *error) {
    XCTAssertNil(error);
    [batchExpectation fulfill];
  }];
  [self awaitExpectations];
  printf("--------------------data written\n");
 
  // Configure new Firestore instance pointing to the same projectId.
  FIRFirestore *firestore = doc1.firestore;
  FIRApp *app = firestore.app;
  NSString *appName = @"newapp";
  FIROptions *options = app.options;
  [FIRApp configureWithName:appName options:options];
  FIRApp *app2 = [FIRApp appNamed:appName];
  FIRFirestore *firestore2 = [self firestoreWithApp:app2];
 
  // Delete documents from new Firestore instance.
  FIRWriteBatch *batch2 = [firestore2 batch];
  batchExpectation = [self expectationWithDescription:@"batch deleted"];
  [batch2 deleteDocument:[firestore2 documentWithPath:doc1.path]];
  [batch2 deleteDocument:[firestore2 documentWithPath:doc2.path]];
  [batch2 deleteDocument:[firestore2 documentWithPath:doc3.path]];
 
  [batch2 commitWithCompletion:^(NSError *error) {
    XCTAssertNil(error);
    [batchExpectation fulfill];
  }];
  [self awaitExpectations];
  printf("--------------------data deleted\n");
}

 

Revise this Paste

Your Name: Code Language: