Trying to retrieve data from mongoDB using the find()
function, which should return objects in an array format. However, encountering an issue where the desired data is not showing up in the array and instead returning undefined
.
Here is the Object Array:
[
{
_id: new ObjectId("635fa2d24f33bf4626211990"),
timestamp: '2022-10-30T08:41:06.826Z',
content: 'something here',
published: 'false'
}
]
let data = await submissionSchema.find({ published: "false" }).exec();
The variable data
holds the response retrieved from the database, containing the Object Array mentioned above. When using console.log(data[0])
, everything displays correctly without the square brackets. But when accessing data[0].content
, it returns undefined
instead of 'something here' as expected. Any insights on this issue would be greatly appreciated.