Home » Javascript » What is the most optimal way to push different items to arrays in each document in mongodb?

What is the most optimal way to push different items to arrays in each document in mongodb?

Posted by: admin November 1, 2017 Leave a comment

Questions:

i.e. I have such collections:

   { a: [2] }
   { a: [3] }
   { a: [4] }

And I want it to become like that

   { a: [2, 4] }
   { a: [3, 9] }
   { a: [4, 16] }

How am I supposed to do that in one query?

Answers: