Reputation:
I have a webb app for adding data to firestore, I can add with the code below but I want to use the user id which user signed in, I have the "uid"
//saving data
$('#form').submit(function(e){
e.preventDefault();
let name = $('[name = name]').val();
let cityLAT = $('[name = cityLAT]').val();
let cityLONG = $('[name = cityLONG]').val();
db.collection('campaigns').add({
name: name,
cityLAT: cityLAT,
cityLONG: cityLONG
});
$('[name = name]').val('');
$('[name = cityLAT]').val('');
$('[name = cityLONG]').val('');
})
Upvotes: 1
Views: 1690
Reputation: 317487
It's not totally clear what you're asking, but it sounds like you don't want to use the automatically generated document ID provided by add()
. If you want to use your own document ID, simply build a reference to that document, and call set()
on it.
const ref = db.collection('campaigns').doc(uid); // whatever ID you want here
ref.set({ ... }); // whatever fields you want here.
Upvotes: 1