我正在尝试更新Firebase数据库中的单个节点,但我的方法是添加两个节点,一个用混音,一个用只有一个标题。如何仅更新播放列表中的孩子。
public void addToExistingPlaylist(String title) {
Query playlistQuery = mDatabase.child("playlists/" + FirebaseAuth.getInstance().getCurrentUser().getUid()).orderByChild("playlistTitle").equalTo(title);
playlistQuery.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childSnapshot : dataSnapshot.getChildren()) {
Playlist playlist = childSnapshot.getValue(Playlist.class);
ArrayList<Mix> mixes = new ArrayList<Mix>();
if (playlist.getMixes() != null) {
mixes = playlist.getMixes();
}
mixes.add(((MusicDetailFragment)mDashboardDetailFragment).mSelectedTrack);
playlist.setMixes(mixes);
DatabaseReference playlistRef = mDatabase.child("playlists/" + FirebaseAuth.getInstance().getCurrentUser().getUid()); //save this mix under mixes --> userUid -- new song
playlistRef.push().setValue(playlist).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()) {
Snackbar newPlayListAddedSnack;
newPlayListAddedSnack = Snackbar.make(mCoordinatorLayout, getString(R.string.song_added_to_existing_playlist), Snackbar.LENGTH_LONG);
newPlayListAddedSnack.show();
} else {
Snackbar errorSnack;
errorSnack = Snackbar.make(mCoordinatorLayout, getString(R.string.error_processing_request), Snackbar.LENGTH_LONG);
errorSnack.show();
}
}
});
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
alert.dismiss();
}
答案 0 :(得分:0)
删除push()。您的代码应该是
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=C: \Users\g_jes\Documents\Gilberte Jessie\aspjProject\App_Data\Database.mdf;Integrated Security=True");