我是firebase的初学者,我试图找到一个值为NULL的Single ALLOTED子项,并尝试仅使用location键更新一些值。即使我已经使用了limitToFirst (1)ALLOTTED为NULL的所有数据都会更新。我已经绞尽脑汁待了很长一段时间,非常感谢任何帮助。我的firebase数据库: ![] [1]
final FirebaseDatabase database =FirebaseDatabase.getInstance();
final DatabaseReference myRef = database.getReference("LOCATION/"+s.getSelectedItem().toString());
Query query = myRef.orderByChild("ALLOTED").equalTo("NULL").limitToLast(1);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot childDataSnapshot : dataSnapshot.getChildren()) {
slot =childDataSnapshot.getKey();
q=""+ myRef.child(slot).child("ALLOTED").setValue(Plateno.getText().toString());
w=""+ myRef.child(slot).child("DATE").setValue(sDate);
e= ""+myRef.child(slot).child("TIME").setValue(time);
r=""+ myRef.child(slot).child("LIMIT").setValue(limit.getSelectedItem().toString());
break;
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
Toast.makeText(getApplicationContext(), "NO SPACE AVAILABLE", Toast.LENGTH_LONG).show();
}
});
}
});
[1]:contextHandler