Search in sources :

Example 1 with FieldPath

use of com.google.cloud.firestore.FieldPath in project java-firestore by googleapis.

the class ITSystemTest method deleteNestedFieldUsingFieldPath.

@Test
public void deleteNestedFieldUsingFieldPath() throws Exception {
    DocumentReference documentReference = randomColl.document("doc1");
    documentReference.set(map("a.b", SINGLE_FILED_MAP_WITH_DOT)).get();
    DocumentSnapshot documentSnapshots = documentReference.get().get();
    assertEquals(SINGLE_FILED_MAP_WITH_DOT, documentSnapshots.getData().get("a.b"));
    FieldPath path = FieldPath.of("a.b", "c.d");
    documentReference.update(path, FieldValue.delete()).get();
    documentSnapshots = documentReference.get().get();
    assertNull(documentSnapshots.getData().get("c.d"));
}
Also used : QueryDocumentSnapshot(com.google.cloud.firestore.QueryDocumentSnapshot) DocumentSnapshot(com.google.cloud.firestore.DocumentSnapshot) FieldPath(com.google.cloud.firestore.FieldPath) DocumentReference(com.google.cloud.firestore.DocumentReference) Test(org.junit.Test)

Aggregations

DocumentReference (com.google.cloud.firestore.DocumentReference)1 DocumentSnapshot (com.google.cloud.firestore.DocumentSnapshot)1 FieldPath (com.google.cloud.firestore.FieldPath)1 QueryDocumentSnapshot (com.google.cloud.firestore.QueryDocumentSnapshot)1 Test (org.junit.Test)1