Sunday, 2 April 2017

Transfer an array element from one document to another in Mongoose

I have an object in an array in a Mongoose model. I want to take one object from a document and put it in another document. At the same time I want the original document to have the second document's object. In other words I want to swap the documents between them.

This requires me to do findOneAndUpdate() four times because I have to push 2 objects into an array and pull 2 objects from the array.

Is there a better/more efficient way to accomplish this?



via JohnSnow

No comments:

Post a Comment