I noticed a very strange behavior when creating a document
export const questionSchema: Schema<IQuestion> = new Schema<IQuestion>(
{
questionLevel: {
type: Schema.Types.Number,
index: true
},
answer: {
type: Schema.Types.String
},
translations: [
{
language: {
type: Schema.Types.String
},
question: {
type: Schema.Types.String
}
}
]
},
{ timestamps: true, collection: EDb.QUESTION_MODEL_NAME, minimize: false }
);
When I try to save a new document:
new this.model(newData).save()
The document is created but without an array
But if i change the code to
const newData: any = new this._model();
for (const key in data) {
newData[key] = data[key];
}
return newData.save();
everything starts to work right