-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Nested arrays using of
result in the incorrect schema type
#14416
Comments
const mongoose = require('mongoose');
const { Schema } = mongoose;
const assert = require('assert');
(async () => {
const schema = new Schema({
nums: [{ type: Array, of: Number }],
tags: [{ type: 'Array', of: String }],
subdocs: [{ type: Array, of: Schema({ name: String }) }]
});
assert.equal(schema.path('nums.$').caster.instance, 'Number'); // actually Mixed
assert.equal(schema.path('tags.$').caster.instance, 'String'); // actually Mixed
assert.equal(schema.path('subdocs.$').casterConstructor.schema.path('name').instance, 'String'); // actually Mixed
console.log('done');
})(); |
quick correction: in the third
|
fix: array schema definitions with `of` keyword
I took a look and the issue is that we don't support |
Yeah, it's been in the documentation here for a while, and that's how I hit the issue
(i thought i mentioned that in my original comment, but looks like i missed that. whoops!) |
Prerequisites
Mongoose version
7.6.9
Node.js version
20.6.1
MongoDB server version
5.x
Typescript version (if applicable)
5.2.2
Description
With a schema definition of
the resulting casters result in
Mixed
rather than the appropriate type.Steps to Reproduce
See my updated tests at master...forivall:mongoose:forivall/nested-array-of
.patch
Expected Behavior
The casters should be the correct schema types.
The text was updated successfully, but these errors were encountered: