You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Mongoose Node.JS ODM
Hello everyone, i am just trying to update my model with the following way - $push ObjectId to array if value not exist and $pull it if not exist ?
Is it pissible? I know that i can use $addToSet if value not exist in array... but how can i remove the value if it exist, in the same query ?
thx. a lot!
Richard Bateman
unread,
Jul 18, 2017, 1:38:04 AM7/18/17
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to mongoo...@googlegroups.com
You might want to ask this in a more generic mongodb group, since it's
not a mongoose-specific question.
That said, I can't think of a way that you could do that; what you
could do is use an unorderedbulkoperation and add two steps: one that
searches for records where the value exists and does a $pull and one
that searches for records which don't contain it and does a $push,
then execute it together.
You could do the same thing but slightly less efficiently just with
two update commands.