I asked a question about a similar topic and it is answered, but have some problems again so they told me to ask under another topic.
I'm trying to add data to the Firestore cloud with UID. I have the UID, and add with UID without a problem, but when I want to add another one it deletes the old data and rewrites on it. I want to add multiple data under the same UID.
$('#form').submit(function(e) {
e.preventDefault();
let name = $('[name = name]').val();
let cityLAT = $('[name = cityLAT]').val();
let cityLONG = $('[name = cityLONG]').val();
let user = firebase.auth().currentUser;
let uid;
if(user != null) {
uid = user.uid;
}
const ref = db.collection('campaigns').doc(uid);
ref.set({ name: name,
cityLAT: cityLAT,
cityLONG: cityLONG },{ merge: true });
$('[name = name]').val('');
$('[name = cityLAT]').val('');
$('[name = cityLONG]').val('');
.set()
will replace whatever data is currently stored in your document with the new data that you provide. It is possible that you will need a solution using.update()
, but it is unclear what you are trying to achieve. What do you expect the data in Firestore to look like after you "add another one"? - Herohtar