Skip to Main Content

MongoByte MongoDB Logo

Welcome to the new MongoDB Feedback Portal!

{Improvement: "Your idea"}
We’ve upgraded our system to better capture and act on your feedback.
Your feedback is meaningful and helps us build better products.

Status Submitted
Categories Database
Created by Guest
Created on Sep 20, 2022

$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);}}'});
  • Attach files
  • Guest
    Sep 20, 2022
    `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.