$addToSetIfNotExists or javascript code as array operator
This would allow for unique if not last entry into arrays.
Preventing:
['one', 'one', 'two', 'three']
But allowing:
['one', 'two', 'three', 'one']
Or perhaps (to run js code on the array at the db):
`.update({}, {$js: {'array_field': 'var last = ""; for (var key in array) {if (array[key] === last) {array.splice(key);}}'});
-
Andrew commented
`array` in the javascript should be `this.fieldValue`.
The `this` object in the script scope should at least have `{fieldValue: ['one','two'], fieldName: 'nameOfArray'}`.
similar but off topic:
This is in line with the required `eval()` global scope fix, if and when javascript requires `.bind()` to access variables in the outer `eval()` scope, fixing that access problem in the language using the existing `.bind()` construct.