databaseReference:
Im trying to save data to my firebase realtime database and I need my key to be the users ID and not the random generated unique key I tried child but still got some random keys any help? this is the method I currently have
async componentWillMount() {
const {data} = await Contacts.getContactsAsync({
fields: [Contacts.Fields.PhoneNumbers],
});
this.setState({dataSource: data.map(contact => ({...contact, key: contact.number}))});
const contacts = data.filter(d => d.phoneNumbers);
contactsToUpload.forEach(contact => {
const number = contact.phoneNumbers[0].number.replace(/\D/g, '');
const ref = firebase.database().ref('/Contacts/' + number);
try {
ref.push(contact.name);
} catch (error) {
console.log(error);
}
});
}
//Currently have
"Contacts" : {
"5554787672" : {
"-LWIlxwIETK5UR3O5GkR" : "Daniel Higgins Jr.",
"-LWImsOurEVDOE-KrkVw" : "Daniel From School"
}
//Needed
"Contacts" : {
"5554787672" : {
"UserId1" : "Daniel Higgins Jr.",
"UserId2" : "Daniel From School"
}
contactsToUpload
populated/initialized? Note that it's easiest to help if the MCVE you share is standalone, so has no external dependencies beyond what you shared.const ref = firebase.database().ref('/Contacts/' + number); try { ref.set(contact.name);
now.