I reaslied after sending data to my database that you cannot organised chronologically without the timestamp. I am therefore trying to update my data with the time stamp, when trying the code below it says that update is not a function.
I am unsure where to put this update function to try add the timestamp to the data in firestore.
function sendRate() {
var selected = JSON.parse(window.sessionStorage.getItem("selected"));
var answers = JSON.parse(window.sessionStorage.getItem("answers"));
var firebaseConfig = {
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const db = firebase.firestore();
db.collection("user").update({
timestamp: firebase.firestore.FieldValue.serverTimestamp()
})
db.collection("user").doc("2afc").set(answers)
db.collection("user").doc("rated").set(selected)
.then(function () {
window.location.href =("postExperiment.html")
})
.catch(function (error) {
console.error("Error writing document: ", error);
})
}
}