I'm using vue and firebase/firestore in my project. The data that I want to send to back-end is direct nested arrays like bellow:
data() {
return {
product: {
name: null,
price: null,
description: null,
images: [] // this is an array that I am working with
},
thumbImgPath: '', // variable to store some path string
bigImgPath: '', // variable to store some path string
count: 0 // pointer
}
}
So when I press a button to fire the function saveNewProduct()
, I push an array into the images
array like so:
saveNewProduct() {
this.product.images.push([this.bigImgPath, this.thumbImgPath])
}
I then get the following error when saving to Firestore:
Function DocumentReference.set() called with invalid data. Nested arrays are not supported.
After some research online, I found that it's possible to add to the nested array indirectly as described in this answer and this.
So I basically created an array of objects, where each object has a paths
field and it stores an array.
Below I imitate multiple calls of a saveNewProduct()
function:
saveNewProduct() {
this.product.images[this.count] = {paths: []};
this.product.images[this.count].paths.push(['BigPath1', 'smallPath1'])
this.count++;
this.product.images[this.count] = {paths: []};
this.product.images[this.count].paths.push(['BigPath2', 'smallPath2'])
this.count++;
this.product.images[this.count] = {paths: []};
this.product.images[this.count].paths.push(['BigPath3', 'smallPath3'])
this.count++;
console.log('images path are: ', this.product.images)
}
Why are these indirect nested arrays are not working? Am I doing something wrong here?