2

so I have searched for hours but haven't been able to find an answer to my question, even though what I want to do seems pretty basic and straightforward to me (I am a beginner with coding and databases though, so have mercy on me):

I have an object schema in an express/mongo/mongoose app with three levels of nestedness that looks like this:

var stepSchema = new mongoose.Schema({
    text: String,
    duedate: Date,
});

var noteSchema = new mongoose.Schema({
    note: String,
    steps: [
        stepSchema
    ]
});


var UserSchema = new mongoose.Schema({
    username: String,
    password: String,
    notes: [
        noteSchema
        ]
});

As you can see, there are several levels of nested objects/subdocuments.

My question is: how can I push a new instance into the "steps" array, which is the "deepest" level of nestedness? Or, for that matter, remove one from the same level? This only seems to be working for the first level of nestedness.

I am building an app where every user (first level) has notes, and each note (second level) can have several steps(third level).

I have managed to push new notes into the notes array of the user model, but I have not been able to push steps into the steps array of the notes array. The data comes from a form the user interacts with, if that is of any relevance.

Thanks in advance for your help!

nikobo
  • 21
  • 2
  • Possible dupe of https://stackoverflow.com/q/23577123/2683814 – s7vr Aug 17 '18 at 22:41
  • Possible duplicate of [Updating a Nested Array with MongoDB](https://stackoverflow.com/questions/23577123/updating-a-nested-array-with-mongodb) – Ashh Aug 18 '18 at 02:30
  • @Veeram this is not a duplicate of either. You are referencing an implementation that uses MongoDB native driver. This question is using the Mongoose ORM. I have the same question as OP. – Len Joseph May 21 '19 at 20:22
  • @Fanpark this is not a duplicate of either. You are referencing an implementation that uses MongoDB native driver. This question is using the Mongoose ORM. I have the same question as OP. – Len Joseph May 21 '19 at 20:22

0 Answers0