-
-
Save kkozionov/44e9a902637b9d7211d9203f91c37369 to your computer and use it in GitHub Desktop.
Mongoose plugin for keeping unique ObjectId ref Arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(schema, options) { | |
schema.method('addUniqueRef', function(field, item) { | |
if(this[field].indexOf(item) < 0) this[field].push(item); | |
}); | |
schema.method('removeUniqueRef', function(field, item) { | |
this[field].splice(this[field].indexOf(item)); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment