I have a DB named StarsGallery that includes objects with multiple array fields (each field is an array of customized image objects with hash value for each image) for each object that is inserted we first generate a hash value for the image and then checks that the hash value doesn't exist already (Happens when someone is trying to insert the same picture twice)... and this query iterates all the hash values of all the arrays of each star object...which takes a lot of time (The time is the problem that I'm trying to solve).
to make things more clear this is how object looks like:
starObject = {
id: ObjectId(...),
comedyImages:[{id:..., hashValue:...,},{id:..., hashValue:...,}],
dramaImages:[{id:..., hashValue:...,},{id:..., hashValue:...,}],
animationImages:[{id:..., hashValue:...,},{id:..., hashValue:...,}]
}
Is there a good way to check that I don't insert the same hash value twice? I thought about maybe make hash value unique or put an index on the value (but the index needs to be for a specific item in a specific array... which makes it not so helpful) but I'm not sure what is the best solution...
Thanks in advance! :)