mongoose subdocument unique code example
Example: mongoose unique subdocument
Model.update({
_id: '576328595b2880f831413b92',
'subdocs.name': {
$ne: 'Unique Name'
}
}, {
$push: {
subdocs: {
name: 'Unique Name'
}
}
}).then((raw) => {
// check raw.nModified value
}).catch(next);