Closed
Description
Run the following code in mongoose 5.7.5:
#!/usr/bin/env node
(async function () {
const mongoose = require('mongoose');
mongoose.plugin((schema) => {
schema.options.versionKey = false;
schema.options.minimize = false;
schema.options.strict = 'throw';
schema.options.strictQuery = 'throw';
});
mongoose.connect('mongodb://localhost:27017/test', {useNewUrlParser: true});
const schema = new mongoose.Schema({
_id: {
type: mongoose.Schema.Types.ObjectId,
default: () => mongoose.Types.ObjectId(),
required: true
},
operations: {
type: [new mongoose.Schema({
_id: {
type: mongoose.Schema.Types.ObjectId,
default: () => mongoose.Types.ObjectId(),
required: true
},
action: {
type: String,
required: true
}
}, {
discriminatorKey: 'action'
})],
default: [],
required: true
}
});
schema.path('operations').discriminator(
`asd/do-something`,
new mongoose.Schema({
wall: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
pitchPath: {
type: new mongoose.Schema({
_id: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
pitch: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
path: {
type: [{
_id: false,
x: {
type: Number,
required: true
},
y: {
type: Number,
required: true
},
visible: {
type: Boolean,
default: true,
required: true
}
}],
default: undefined,
required: true
}
}),
default: undefined,
required: true
}
})
);
const Model = mongoose.model('test', schema);
const instance = new Model();
instance.operations.push({
action: 'asd/do-something',
wall: mongoose.Types.ObjectId(),
pitchPath: {
_id: mongoose.Types.ObjectId(),
pitch: mongoose.Types.ObjectId(),
path: [
{x: 0, y: 0, visible: true},
{x: 1, y: 1, visible: true}
]
}
});
console.log(instance.operations[0].pitchPath);
})();
This is the output:
{
_id: 5db02ad12f42a48fa5cc1d31,
pitch: 5db02ad12f42a48fa5cc1d32,
path: [
{ visible: true, _id: 5db02ad12f42a48fa5cc1d34, x: 0, y: 0 },
{ visible: true, _id: 5db02ad12f42a48fa5cc1d33, x: 1, y: 1 }
]
}
Notice that entries in the path
array have ids assigned, but there's _id: false
in the schema.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
test: repro #8274