I cannot delete object inside my array of object in a document from Firestore.
I have tried that
JavaScript
x
20
20
1
const obj = product;
2
const user_post = await this.checkOwnerPost();
3
4
console.log(obj);
5
6
if (user_post){
7
await this.firestore
8
.collection('testCollection')
9
.doc(user_post.doc_id)
10
.update({
11
products: firebase.firestore.FieldValue.arrayRemove(obj)
12
.then(() => {
13
console.log("Document successfully updated!");
14
return true;
15
}).catch((error) => {
16
console.log(error);
17
return false;
18
})
19
});
20
}
JavaScript
1
8
1
Console.log(obj) = {
2
"description": "1",
3
"key": 1,
4
"name": "first",
5
"picture": "https://firebasestorage.googleapis.com/v0/b/url",
6
"price": 1,
7
}
8
Here the error msg:
JavaScript
1
5
1
[Unhandled promise rejection: TypeError: undefined is not a function (near '..._firebase.default.firestore.FieldValue.arrayRemove(obj).then...')]
2
at node_modules/lodash/lodash.js:10487:35 in debounced
3
at [native code]:null in flushedQueue
4
at [native code]:null in callFunctionReturnFlushedQueue
5
Someone can help me ? Or do you have any ideas how can i do for delete and update a object inside an array ?
EDIT: Is fix, it was bad formating of JS code
Advertisement
Answer
Fix
I was a bad formating of the JS Code.
The working code is:
JavaScript
1
14
14
1
if (user_post){
2
await this.firestore
3
.collection('testCollection')
4
.doc(user_post.doc_id)
5
.update({products: firebase.firestore.FieldValue.arrayRemove(obj)})
6
.then(() => {
7
console.log("Document successfully updated!");
8
return true;
9
}).catch((error) => {
10
console.log(error);
11
return false;
12
});
13
};
14