If indexed field's value exists upon insert, insert the field as value + 1

Hey,
I was wondering if there is a way to insert a document with an indexed field value (not _id), and if the value exists already, then insert it with some change.
For example:

=== Existing Document ===
{
   name: 'abc',
   _id: 123
}

=== Document To Insert ===
{
   name: 'abc',
   _id: 456
}

=== Final Result ===
{
   name: 'abc',
   _id: 123
},
{
   name: 'abc #2',
   _id: 456
}

Thanks

Hi @Efrat_Harel ,

There is no way I know of in the server to do this logic.

Usually, you can either query for that value and if exist have an application logic to change it, or wait for a unique index error and add the additional post fix.

Ty

1 Like

That’s what I was afraid of, was hoping there is some way I’m unaware of.
Thanks!