version:
Mongoose = 4.13.14
mongodb = 3.2.20
problem description
for example, use mongoose to create a new document, and fields of type Mixed (or Object) cannot be inserted into the database even if the default value is set. What is the reason for this?
related codes
const Mixed = mongoose.Schema.Types.Mixed;
//
document = {
version: {type: Number, default: 0},
data: {type: Mixed, default: {}},
};
//schema
...
//
testData = {
version: 1,
data: {}
}
testDoc = new (mongoose.model(document))(testData);
//testDoc{version:1}testDoc.data{}
checked the relevant documents but did not find a clue, please do not hesitate to comment ah, thank you!