Reputation: 351
I'm trying to delete a node from Firebase database but nothing happens.
This is my code:
FileInputStream serviceAccount = new FileInputStream(keyPath);
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl(databaseUrl)
.build();
FirebaseApp.initializeApp(options);
DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
ref.child("Users").child(uid).child("name").removeValue()
This is the output:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J:See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.09-02-2018 05:43:53 PM - [START] - Start action : Statement - serviceAccount = new java.io.FileInputStream(keyPath) 09-02-2018 05:43:53 PM - [END] - End action : Statement - serviceAccount = new java.io.FileInputStream(keyPath) 09-02-2018 05:43:53 PM - [START] - Start action : Statement - options = new com.google.firebase.FirebaseOptions$Builder().setCredentials(com.google.auth.oauth2.GoogleCredentials.fromStream(serviceAccount)).setDatabaseUrl(databaseUrl).build() 09-02-2018 05:43:53 PM - [END] - End action : Statement - options = new com.google.firebase.FirebaseOptions$Builder().setCredentials(com.google.auth.oauth2.GoogleCredentials.fromStream(serviceAccount)).setDatabaseUrl(databaseUrl).build() 09-02-2018 05:43:53 PM - [START] - Start action : Statement - com.google.firebase.FirebaseApp.initializeApp(options) 09-02-2018
05:43:53 PM - [END] - End action : Statement - com.google.firebase.FirebaseApp.initializeApp(options) 09-02-2018
05:43:53 PM - [START] - Start action : Statement - ref = com.google.firebase.database.FirebaseDatabase.getInstance().getReference()
09-02-2018 05:43:53 PM - [END] - End action : Statement - ref = com.google.firebase.database.FirebaseDatabase.getInstance().getReference()
09-02-2018 05:43:53 PM - [START] - Start action : Statement ref.child("Users").child(uid).child("name").removeValue() 09-02-2018
05:43:53 PM - [END] - End action : Statement - ref.child("Users").child(uid).child("name").removeValue() 09-02-2018
05:43:53 PM - [PASSED] - Test Cases/V2/General/Draft 09-02-2018
05:43:53 PM - [END] - End Test Case : Test Cases/V2/General/Draft
As I said, nothing changes on the database.
Any ideas?
Upvotes: 1
Views: 159
Reputation: 351
I eventually found this repository on github: https://github.com/bane73/firebase4j
In the readme file, there is a simple example of writing a value to firebase database by providing only the database url and the data you want to write.
In order to delete a value, just set the value to null:
String url = 'https://project-name.firebaseio.com/users/user1/email'
//Initialize database
Firebase firebase = new Firebase(baseUrl);
//remove email of user1
Map<String, Object> dataMap = new LinkedHashMap<String, Object>();
dataMap.put("some str", null);
firebase.put(dataMap)
Upvotes: 0