Hi, so I have an entry in my collection as such:
{
_id: someID
array: [
{
title: someTitle
data: someOtherData
...
},
{
title: someTitle
data: someOtherData
...
}
]
}
Is there any way for me to create a unique and non-changing _id
field for each element in this array? I understand that the array indexing is already unique, and I don’t have a constraint of duplicates as the data will never result in duplicates (consists of unique hashes).
The reason why I seek the indexing to be unique and non-changing is because I’m using the index to generate a link to some data. Right now it directs to example.com/some_path/userID/0
and the last digit is the index in the array. However, users can modify this data and delete data at an arbitrary index.
That means that if one day you navigate to that link, and the user deletes their item at index 0, the next day when you navigate to that link you’ll be seeing something different (the element at the previous index 1 instead). Or, if you navigate to the last element in the array and the user deletes something before that, it’ll result in a 404.
If I can have a unique ID, then links are preserved over time. I thought of one way of doing this by using an object instead of an array:
{
_id: someID
object: {
{
_id: someUniqueID,
title: someTitle
data: someOtherData
...
},
{
_id: someUniqueID,
title: someTitle
data: someOtherData
...
}
}
}
But I’d prefer to use an array as it seems much more logical than using an object of objects, as I still have the choice of accessing things by index and all the other useful sorting, etc that can be done with an array.
Appreciate any help, thank you!