My question is based on this StackOverflow question
Currently, having a document with embedded array of documents, the
$addToSet operation compare each of the fields of the nested document (or the hash of the nested document. I am not aware how was implemented).
It will be great if we have the possibility to specify key / field that will be used in making the decision whether the document we try to add already exists
The proposed answer in the SO question is fine for adding only one element. Adding more elements the same way (with query for existence of the nested document) may lead to loosing the benefits оф ACID features for working with single document because of the multiple separate update statements that should be executed. Even bulk updates don’t fix the problem.
Looking at the question, It seems to me that It is a popular one. I am wandering whether adding such feature for $addToSet operation have been ever discussed. It will be nice if it is available in the future and fix the problems described above.
P.S. I know that I can use multi-document transactions but I don’t think using them for such case is appropriate.