Skip to content Skip to sidebar Skip to footer

How To Change Sub Document After Finding With Mongoose

I have some code like below using mongoose. var mongoose = require('mongoose'); var Schema = mongoose.Schema; mongoose.connect('mongodb://localhost/hoge'); var UserSchema = new Sc

Solution 1:

Sorry, I've resolved myself.

The problem is the order of declarating Schemas.

It worked if I tried this change.

/* first, children's schema */varChildSchema = newSchema({
  name: String,
}, {_id: false});

/* seconds, parent's schema */varUserSchema = newSchema({
  name: String,
  children: [ChildSchema],
});

Post a Comment for "How To Change Sub Document After Finding With Mongoose"