I have an array of objects in an entity in a DB record.
I want to push new object to that array, but I don't want to push the same object multiple times. I know I can use $addToSet, but the problem occurs that in each object I add timestamp, so this method doesn't distinguish that the object already in the array, it fully compare the objects and if the timestamp has changed it will add it twice so I will have:
[
{ a: 1, timestamp: X },
{ a: 1, timestamp: X+Y }
]
As you can see I already have a, but since timestamps has changed, for $addToSet it is okay to add this object once again.
How can I check agains specific fields, so I will check only against a property - ignoring the timestamp?