2017-02-10 1 views
3

왜이 오류가 발생합니까? 디버그 모드에는 키에 특수 문자가 없으며 '.'가없고 경로에 필요한 '/'만 있습니다. 그것은 잘 작동하고 있었고, 나는 데이터베이스를 지우고 타이틀의 오류로 다시 실행했습니다. 내 코드 :

DatabaseReference databaseReference = FirebaseDatabase.getInstance(). getReference(); 여기

String animalUid = animal.getUid(); 

if (animalUid == null) { 
    animalUid = databaseReference.push().getKey(); 
} 

Map<String, Object> animalData = new HashMap(); 


if(animal.getFavorites()!=null) { 
    for (Map.Entry<String, Boolean> entry : animal.getFavorites().entrySet()) { 
     animalData.put("users-favorites-animals/" + entry.getKey() + "/" + animalUid, animal); 
    } 
} 

animalData.put("users-animals/" + animal.getOwnerUid() + "/" + animalUid, animal); 
animalData.put("animals/" + animalUid, animal); 

databaseReference.updateChildren(animalData).addOnCompleteListener(new OnCompleteListener() { 
    @Override 
    public void onComplete(@NonNull Task task) { 
     listener.onSaveAnimalSucess(animal); 
    } 
}).addOnFailureListener(new OnFailureListener() { 
    @Override 
    public void onFailure(@NonNull Exception e) { 

     if (e instanceof FirebaseException) { 
      listener.onSaveAnimalError(""); 
      return; 
     } 

     listener.onConnectionError(); 
    } 
}); 

animalData 키 updateChildren 앞에 오는 방법 :없이

"동물/-Kcd_8Tif5EPYUhsceeH"

"사용자 - 동물/LoQ9Bkjs2yVC95nFGyo1ft4cqdB2/-Kcd_8Tif5EPYUhsceeH"

심지어 내 예전의 코드 다중 데이터 업데이트가 작동하지 않으며 동일한 오류가 발생합니다. 나는 무슨 일이 벌어지고 있는지 전혀 모른다.

+3

키는 /를 포함하지 않아야한다. 여기서 명확하지 않은 점은 무엇입니까? –

+1

이것은 키가 아니며 firebase가 지원하는 깊은 경로이지만 이전 firebase 버전으로 key를 계속 호출합니다. https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html –

+1

이전 버전의 firebase (Android (2.4.0))에서 블로그를 읽는 중입니다.). 최신 버전은 10.0.x입니다 ... 최신 API를 확인하십시오 –

답변

0

당신이 도움이 될지 확실하지 않지만 내 개인적인 개체와 조화되는 구성 요소를 사용하고 있습니다. 예를 들어, primeng 자동 선택 상자에 '_ $ visited'가 내 데이터에 추가됩니다. 다른 사람이 같은 문제를 겪고있어 실제로 개체에 이러한 종류의 키가 필요하지 않은 경우 다음 기능을 호출하는 것이 좋습니다. (너는 그것을 위해 lodash가 있어야한다)

private makeObjectGreatAgain(object: any) { 
// removing undefined values from any arrays! 
// and some variables which are added by different components 
// firebase not allowed keys: ".", "#", "$", "/", "[", or "]" 
object = JSON.parse(JSON.stringify(object), (key, val) => { 
    if (!_.includes(key, '.') && !_.includes(key, '#') && !_.includes(key, '$') && 
    !_.includes(key, '/') && !_.includes(key, '[') && !_.includes(key, ']')) { 
    return val; 
    } else { 
    console.log('removing invalid key: ' + key + ' val: ' + val); 
    } 
}); 
return object; 
} 
관련 문제