These are chat archives for Automattic/mongoose

3rd
Jun 2016
Mohamed Nasrullah
@nasr18
Jun 03 2016 10:50
is it possible to update multiple array field inside a single $addToSet??
Paul "Joey" Clark
@joeytwiddle
Jun 03 2016 14:39
I think you can send two $addToSet commands in one request.
Mohamed Nasrullah
@nasr18
Jun 03 2016 14:41
i did that. but dint get what i want. if array contains what i'm pushing means, it should not add to that array. if not means, it should add that value.
Paul "Joey" Clark
@joeytwiddle
Jun 03 2016 15:16
Are you pushing a primitive value, or an object? Could you show an example?
Mohamed Nasrullah
@nasr18
Jun 03 2016 15:40
pushing array.
wait i wil post my code
Article.findByIdAndUpdate(article._id, {
            $addToSet:{category:{$each:categoryIds}},
            $addToSet:{tags:{$each:tagIds}},
            $addToSet:{location:{$each:locationIds}}
        }, {new:true}).exec(function(err, article) {
            if(err) console.log('addtoset bulkupdate findByIdAndUpdate err:', err);
            else bulkupdatedArticles.push(article);
            cb();
        });
Paul "Joey" Clark
@joeytwiddle
Jun 03 2016 15:51
And what goes wrong? Some of them are added twice?
Mohamed Nasrullah
@nasr18
Jun 03 2016 15:52
yeah and sometimes empty array. @joeytwiddle