从 firebase 数据库中删除一个值
remove a value from firebase database
我正在尝试从 Firebase 数据库中删除一个节点,但没有任何反应。
这是我的代码:
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()
这是输出:
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
正如我所说,数据库没有任何变化。
有什么想法吗?
我最终在 github 上找到了这个存储库:https://github.com/bane73/firebase4j
在自述文件中,有一个通过仅提供数据库 url 和您要写入的数据来将值写入 firebase 数据库的简单示例。
为了删除一个值,只需将该值设置为空:
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)
我正在尝试从 Firebase 数据库中删除一个节点,但没有任何反应。
这是我的代码:
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()
这是输出:
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
正如我所说,数据库没有任何变化。
有什么想法吗?
我最终在 github 上找到了这个存储库:https://github.com/bane73/firebase4j
在自述文件中,有一个通过仅提供数据库 url 和您要写入的数据来将值写入 firebase 数据库的简单示例。
为了删除一个值,只需将该值设置为空:
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)