-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"is not a function" validation error with nested Schema #9438
Labels
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
Milestone
Comments
vkarpov15
added
the
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
label
Sep 22, 2020
9438.js'use strict';
const mongoose = require('mongoose');
const { Schema } = mongoose;
const assert = require('assert');
const categorySchema = new Schema(
{
name: String,
// categoryUrl: String, // Makes tests pass
categoryUrl: { type: String, required: true }, // Makes test fail
isSelected: Boolean
},
{ _id: false }
);
const siteSchema = new Schema({ categoryUrls: [categorySchema] });
const Site = mongoose.model('Site', siteSchema);
const site = new Site({
categoryUrls: [
{ name: 'A', categoryUrl: 'B', isSelected: false }
]
});
const err = site.validateSync();
console.log(err);
assert.ok(err == null);
console.log('All assertions passed.'); Output
Seems like mongoose uses an internal function |
AbdelrahmanHafez
added
confirmed-bug
We've confirmed this is a bug in Mongoose and will fix it.
and removed
needs repro script
Maybe a bug, but no repro script. The issue reporter should create a script that demos the issue
labels
Sep 23, 2020
vkarpov15
added a commit
that referenced
this issue
Sep 23, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you want to request a feature or report a bug?
bug
Possibly related to issue #8190
What is the current behavior?
returns validation error while trying to save a new doc (properly formatted) in DB :
[SiteController] createSite failed with error Site validation failed: categoryUrls.0.categoryUrl: this.isSelected is not a function
What is the expected behavior?
should save new docs properly.
It took me quite some time to figure it werenot the 'isSelected' property making mongoose fail, but the property just above and its required check ...
Not sure if this could be qualified as a "bug", but the error message is really misleading ...
How should i make this nested propertty
categoryUrl
as required without it making the whole Schema validation fail ?What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS: 14.11.0
Mongoose: 5.10.6
MongoDB Server: 4.4.1
The text was updated successfully, but these errors were encountered: