Open kevinresol opened 8 years ago
This is what I get if I log schemaPath
at line 261
Mixed {
path: 'waitingList',
instance: 'Mixed',
validators: [],
setters: [],
getters: [],
options: { __type__: { current: [Object], history: [Object] } },
_index: null }
So, at line 285 the assignment schema = schemaPath.schema
will cause schema
become undefined
, causing the aforementioned crash.
What is __type__
?
It is the typeKey http://mongoosejs.com/docs/guide.html#typeKey
If you can add a failed test to the bugs section, it would help.
Where can I find out more about this usage of type
?
For example, what is the difference between
var ItemSchema = new Schema({
waitingList: {
type: {
current: {
type: [{
date: {type: Date},
user: {type: Number, ref: "User.bug47"},
}]
}
}
}
})
and
var ItemSchema = new Schema({
waitingList: {
current: [{
date: {type: Date},
user: {type: Number, ref: "User.bug47"},
}]
}
})
I am not sure if there are any extra information out there other than the link I posted and the source code. I think mongoose will force treating the the field as a type declaration if the field name matches the typeKey option (which defaults to "type")
AFAIK, there should be no different between the two examples, functionally.
Is this has solution?My code has same problems if key was named "type".
@Yuliang-Lee your problem is probably unrelated to deep-populate You may need to specify typeKey in the schema options.
@kevinresol I try to modify typeKey but deep-populate occurs error
I have a schema like this:
So, in essence a sample document looks like this:
In that case I want to deep populate
user
, but if I specify the path as"waitingList.history.user"
. The plugin crashes with errorTypeError: Cannot read property 'paths' of undefined
at this position: https://github.com/buunguyen/mongoose-deep-populate/blob/0080a0949fef38bcb9541b267a55810c14c78d4c/lib/plugin.js#L260For some funny reason I am restricted from declaring sub-schema for those embeded documents. It is possible to make it work in such case?