Method $ push does not work (MongoDB, Mongoose)

0

How about. I'm having a problem I have an array in mongodb, which is supposed to store objects, but I can not add them.

Student.update(mongoose.Types.ObjectId("5bc25777d9dded06a4635430"),{$push:{sanctions:{reason:'test'}}});

It is assumed that mongoose finds the document in the database, and then it would do a push as if it were a normal javascript array. But he does not.

    
asked by Teo villa 15.10.2018 в 17:35
source

1 answer

0

Try this way:

Student.update(
  {_id: "5bc25777d9dded06a4635430"},
  {$push: {sanctions: {reason:'test'}}}
);
    
answered by 24.10.2018 в 18:55