In the algolia documentation, they specify that you can manipulate arrays like this:
// adding
index.partialUpdateObject({
myfield: {
value: 'myvalue',
_operation: 'Add'
},
objectID: 'myID'
})
/removing
index.partialUpdateObject({
myfield: {
value: 'myvalue',
_operation: 'Remove'
}
})
This works well when the array is a string or number. However imagine that I have this document structure, where arrays are actually nested objects:
{
first_name: String,
last_name: String,
subjects: [
{
itemId: String,
title: String,
randomField: String,
dateAdded: Date
}
]
}
In this case the algolia documentation is very unclear. For example, imagine the following scenarios:
randomField field of a particular array item. I want to be able to update a nested array item by itemId.partialUpdateObject.Is this kind of thing possible in Algolia? What would be your recommendations?
It's not possible to add/update/remove a specific attribute of a nested array using the partilUpdateObject function.
You get it right by fetching the object, modifying and updating it after. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With