I use firebase firestore db. This project have two main collection "securecollection" and "publiccollection". The securecollection is where all important data is stored and only accessible to authenticated users. But in order for some information to be visible to guest users, I am copying them into the publiccollection. Then, I want to save the id of this newly created public document in the secure document.
When I write a variable
db.collection('securecollection').doc(secureDocid).update({ inside the query sentence, I get this error:
Uncaught (in promise) TypeError: o.indexOf is not a function
If I write the id as text db.collection('securecollection').doc('7llDqIWlmE5VM69Zzle2').update({, the code works.
Here is my code:
function toggleOlustur(secureDocid) {
const db = firebase.firestore();
db.collection("securecollection").get()
.then(querySnapshot => {
querySnapshot.forEach(doc => {
if (doc.id == secureDocid) {
db.collection("publiccollection").add({
oad: doc.data().oad,
osad: doc.data().osad,
opuan: doc.data().opuan,
odtarih: doc.data().odtarih,
odurum: "1",
})
.then((docRef) => {
db.collection('securecollection').doc(secureDocid).update({
preference: docRef.id
})
});
}
});
});
}
The doc() method expects a string argument, and from the error message it sounds like your secureDocid is not a string value. If you console.log(JSON.stringify(secureDocid)) you can see what it outputs, which might help to figure out the problem.