我正在尝试仅将在一个节点上添加的新数据项复制到另一个节点。但是,它还复制了copyto节点中的现有数据节点。请帮助我如何实现这一点,我试图在这种情况下复制qSet3,以及在Questions节点上添加到userQuestions节点的任何后续节点。
Questions = mDatabase.child("Questions");
userQuestions = mDatabase.child("UserQuestion").child(PhoneNum).child("userQuestions");
moveFirebaseRecord(Questions,userQuestions);
public void moveFirebaseRecord(DatabaseReference fromPath, final DatabaseReference toPath) {
fromPath.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
toPath.setValue(dataSnapshot.getValue(), new DatabaseReference.CompletionListener() {
@Override
public void onComplete(DatabaseError databaseError, DatabaseReference databaseReference) {
if (databaseError != null) {
Toast.makeText(getApplicationContext(), "COPY FAILED", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "COPY SUCCESS", Toast.LENGTH_LONG).show();
}
}
});
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(), "onCancelled- copy fail", Toast.LENGTH_LONG).show();
}
});
}