Closed Aloune92 closed 2 years ago
const mongoose = require('mongoose');
const nestedSchema = new mongoose.Schema({
bar: String
}, { _id: false });
const schema = new mongoose.Schema({
foo: nestedSchema
});
const MyModel = mongoose.model('MyModel', schema);
async function run() {
await mongoose.connect('mongodb://localhost:27017/test');
await mongoose.connection.dropDatabase();
const myModel = await MyModel.create({ foo: {} });
console.log(myModel); // { _id: 61e82a9247bc4b3b51231301, foo: {}, __v: 0 }
}
run();
Do you want to request a feature or report a bug? Bug
What is the current behavior? Empty nested schemas are not minimized.
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?
foo
is stored in db . It should not andmyModel.foo
should not appears in the result of theconsole.log
.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
Node v16.10.0 Mongoose v5.13.9 or v6.1.7 MongoDB v4.4.7