I have a model schema like this:
Collection: {
irrelevant fields,
object: {
more irrelevant fields,
array:
[
{
field1,
field2,
_id: false
}
]
}
}
I want to push to array any object {field1, field2} that does not repeat with field1 already existing in array (in an updateOne query). field2 is constantly updating itself and i have tried addtoset but it considers field2 so it ends up adding another item i don't want to add.
For example:
array:[
{field1: 1, field2: 6},
{field1: 2, field2: 4},
{field1: 3, field2: 1}
]
if i would want to push {field1: 2, field2: 6} it should not let me push it because the field1:2 already exists in array.
(using addtoset, even it does check that the field1:2 already existis, it ends up adding te object because of field2 being different)
array:[
{field1: 1, field2: 6},
{field1: 2, field2: 4},
{field1: 3, field2: 1}
{field1: 2, field2: 6}
]