mongoose: doc.validate is not a function
node_modules\mongoose\lib\schema\documentarray.js:104
doc.validate({ __noPromise: true }, function(err) {
^
TypeError: doc.validate is not a function
- documentarray.js:104
[hypetrain]/[mongoose]/lib/schema/documentarray.js:104:11
- schematype.js:654 DocumentArray.SchemaType.doValidate
[hypetrain]/[mongoose]/lib/schematype.js:654:22
- documentarray.js:77 DocumentArray.doValidate
[hypetrain]/[mongoose]/lib/schema/documentarray.js:77:35
- document.js:1171
[hypetrain]/[mongoose]/lib/document.js:1171:9
- node.js:433 nextTickCallbackWith0Args
node.js:433:9
- node.js:362 process._tickCallback
node.js:362:13
my schema;
var GameStatisticsSchema = new mongoose.Schema({
game: { type: mongoose.Schema.ObjectId, ref: 'Game', required: true }, // associated game subverse.
months: [
{ // monthly viewers
epoch: { type: Number, required: true }, // entry time stamp
weeks: [
{ // weekly viewers
epoch: { type: Number, required: true }, // entry time stamp
days: [
{ // daily viewers
epoch: { type: Number, required: true }, // entry time stamp
hours: [
{ // hourly viewers
epoch: { type: Number, required: true }, // entry time stamp
minutes: [
{ // per minute statistics.
viewers: { type: Number },
channels: { type: Number },
}]
}]
}]
}]
}]
});
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 16 (1 by maintainers)
Commits related to this issue
- test(schema): repro #3816 — committed to Automattic/mongoose by vkarpov15 8 years ago
Hi, I run into this issue for the first time today.
I can’t tell exactly what is gonig on, if I find something I’ll come back.
so far I am not using doc.validate anywhere directly in my code.
and this is failing on a
.save
statement.basically if i
.save()
a document, that has sub documents,and if one of those sub-documents is a plain object instead of a model, i get the error. does this make sense?@vkarpov15
I have create a script to reproduce the problem.
This is reproducing the issue on my system.
@vkarpov15 Sorry for the delayed response. Example of changing array index: