When querying for documents with an array, I'm encountering an issue where the returned documents do not include the array. Below is my code:
Query Code
(async () => {
const data = await Lesson.find({signed: {$exists: true}});
console.log(data[0].signed); # undefined
})();
Model Schema
const lessonSchema = new mon.Schema(
{
day: Number,
startTime: Number,
endTime: Number,
description: {type: String, trim: true},
signed: [mon.Schema.Types.ObjectId]
},
{
collection: 'lessons'
}
);
module.exports = mon.model("Lesson", lessonSchema);
Upon checking the database, I confirmed that the documents indeed have the required array field. However, when executing the query, it retrieves all other data except for the array, even though the array exists in all documents. It's worth noting that there are only two test documents in the database at this time.
Thank you for any insights or assistance provided. Additionally, I discovered that removing the 'signed' property from the schema resolves the issue. Does anyone know why?