New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"FieldValue.delete() is not supported at field" #480
Comments
@alamothe Thanks for raising this issue. I follow your step and able to reproduce this issue. The cause of issue is that To fix these problem exclude pom.xml <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>issue-480</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.firebase</groupId>
<artifactId>firebase-admin</artifactId>
<version>7.0.1</version>
<exclusions>
<exclusion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-firestore</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-firestore</artifactId>
<version>2.1.0</version>
</dependency>
</dependencies>
</project> Sample import com.google.api.core.ApiFuture;
import com.google.auth.oauth2.GoogleCredentials;
import com.google.cloud.ServiceOptions;
import com.google.cloud.firestore.DocumentReference;
import com.google.cloud.firestore.DocumentSnapshot;
import com.google.cloud.firestore.FieldPath;
import com.google.cloud.firestore.FieldValue;
import com.google.cloud.firestore.Firestore;
import com.google.cloud.firestore.FirestoreOptions;
import com.google.cloud.firestore.WriteResult;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutionException;
public class Test {
public static void main(String[] args) throws ExecutionException, InterruptedException, IOException {
FirestoreOptions firestoreOptions =
FirestoreOptions.getDefaultInstance().toBuilder()
.setProjectId(ServiceOptions.getDefaultProjectId())
.setCredentials(GoogleCredentials.getApplicationDefault())
.build();
Firestore db = firestoreOptions.getService();
DocumentReference docRef = db.collection("col1").document("doc1");
Map<String,Object> xyzMap = new HashMap();
xyzMap.put("xyz","data");
Map<String,Object> dotMap = new HashMap();
dotMap.put("184.174.14.109",xyzMap);
Map<String, Object> data = new HashMap();
data.put("abc", dotMap);
ApiFuture<WriteResult> writeResult = docRef.update(data); //NOTE: create doc1 if not exists using docRef.create(data)
System.out.println("Before FieldValue.delete");
DocumentSnapshot documentSnapshot = docRef.get().get();
System.out.println(documentSnapshot.getData());
FieldPath path = FieldPath.of("abc", "184.174.14.109", "xyz");
docRef.update(path, FieldValue.delete()).get();
System.out.println("After FieldValue.delete");
documentSnapshot = docRef.get().get();
System.out.println(documentSnapshot.getData());
}
} Output
Please let us know if this helps! |
Interesting! Thank you for answer. I'm actually pretty sure that we don't need |
Works! Closing now, thanks! |
Environment details
MacOS
11
com.google.firebase:firebase-admin:7.0.1
Steps to reproduce
Exception thrown while trying to delete a field:
Error:
This happens before even reaching the backend, in client code.
I am also wondering if there is any workaround until this is resolved?
The text was updated successfully, but these errors were encountered: