D
D
Daniel Chistyakov2021-09-07 09:30:54
Node.js
Daniel Chistyakov, 2021-09-07 09:30:54

How to push only unique objects to an array using Mongoose?

There is a model:

list: [
    {
      id: { type: Number, required: true, unique: true },
      poster: { type: String, required: true },
      title: { type: String, required: true },
      url: { type: String, required: true },
    },
],


It is necessary that before pushing an object into the Mongoose array, it is checked whether there is an object with the same ID value in the array. Or is it better to do it at home, without Mongoose?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rag'n' Code Man, 2022-01-27
@iDmitriyWinX

Set
UPD: I completely forgot about $addToSetthe update request.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question