I am using pure Javascript to insert documents in a firestore collection without authentication. Reading real time data functions as it should with no trouble but inserting a document doesn't seem to work. What is wrong here?
This is the console output:
firebase-firestore.js:1 Uncaught TypeError: o.indexOf is not a function at Function.hi.q (path.ts:227) at Qd.doc (database.ts:2217) at createDoc (firebase.js:26) at HTMLFormElement.onsubmit (board.html:83)
I tried another onClick method from the javascript by getting the element ID of the button and submitting the click and this is the console log I got:
VM1764 firebase-firestore.js:1 Uncaught TypeError: o.indexOf is not a function at Function.hi.q (VM1764 firebase-firestore.js:1) at Qd.doc (VM1764 firebase-firestore.js:1) at createDoc (VM1765 firebase.js:26) at HTMLButtonElement.document.getElementById.onclick (VM1765 firebase.js:17)
this is JS followed by HTML:
//config
var firebaseConfig = {
apiKey: "...",
authDomain: "...",
databaseURL: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
firebase.initializeApp(firebaseConfig);
firebase.analytics();
document.getElementById("postBtn").onclick = function() { createDoc() };
//insertion
function createDoc() {
var usernameInput = document.getElementById("username_input").value;
var jobTitleInput = document.getElementById("job_input").value;
var timestampInput = Date.now();
firebase.firestore().collection("humans").doc(Date.now()).set({
job: jobTitleInput,
timestamp: timestampInput,
username: usernameInput,
}).then(function() {
console.log('document inserted');
document.getElementById("data_section").innerHTML = '';
fetchAllThreadsByTimestamp();
}).catch(function(error) {
console.error('document insertion error: ' + error);
});
}
<form class="form">
<div class="row">
<div class="col-xs-8 col-md-10 ">
<input type="text" id="username_input" placeholder="username" required/>
</div>
</div>
<br>
<div class="row ">
<div class="col-xs-8 col-md-10 ">
<input type="text" id="job_input" placeholder="job title" required/>
</div>
<div class="col-xs-4 col-md-2">
<button id="postBtn" class="btn">POST</button>
</div>
</div>
</form>