I'm inserting an object in an array of object with mongoose. My object is like:
name: {
type: String,
unique: true,
required: true
},
translations: [{
tag: {
type: String,
unique: true,
required: true
},
meaning: {
type: String,
required: true
}
}]
I would like my code to throw an error when there are already an object in "translation" with the same 'tag' value.
I'm currently doing this :
Language.update(
{name: languageName},
{$addToSet: { 'translations': {
tag: aNewTag,
meaning: aNewTranslation
}}}, {
upsert: false
}, function(err) {
if (err) console.log(err);
else console.log('This is spartaaa!!!');
}
);