I have a collection of settings that I am trying to save for users that login. I'm not finding a built in way to allow me to handle updating timestamps for records that I add.
db = firebase.firestore()
settingsCollection = db.collection('settings')
let userSetting = fb.settingsCollection.doc(this.userId)
//store the settings in firebase
var setWithMerge = userSetting.set({
createdOn: new Date(),
updatedOn: new Date(),
filters: {showTestOrders: show},
userId: this.userId
}, {merge: true}).then(ref => {
//console.log(ref)
}).catch(err => {
console.log(err)
})
According to docs, the .set()
method will create or update records. ( https://firebase.google.com/docs/firestore/manage-data/add-data )
Can someone suggest an efficient way to handle the timestamps? My current approach always updates the createdOn
method since records exist. I'd like to NOT update that record if it already exists. I was hoping there is a convenient way to do this.
Thanks!