Using mongoose against mongodb 2.6 - another issue raised that sounds similar to mine;
https://github.com/LearnBoost/mongoose/issues/1677
I have this piece of code:
$addToSet: {
invite_list: {
$each : [
{ email: 'test@test.com' },
{ email: 'test@test.com' },
{ email: 'test@test.com' },
{ email: 'test@test.com' }]
}
}
which should only store one item but instead its storing 4!
However, changing the query to this
$addToSet: {
invite_list: {
$each : [
'test@test.com',
'test@test.com',
'test@test.com',
'test@test.com' ]
}
}
returns one item, as expected.
Model schema field:
invite_list: [{email: {type: String, trim: true}}],
The query looks like this;
UserModel.findOneAndUpdate(
{
_id: req.params.id,
},
{
$addToSet: {invite_list: { $each : [{ email: 'test@test.com' },
{ email: 'test@test.com' },
{ email: 'test@test.com' },
{ email: 'test@test.com' }] }}
}, function (err, user) {
// morel logic here...
return res.status(200).json(user);
});
http://docs.mongodb.org/manual/reference/operator/update/addToSet/
Is there something Im missing.
Thanks.
J