I am facing an issue with my data returning false in this code snippet. Despite having a console log statement, it indicates that there is no data available. I am specifically looking for a document containing the 'userId', which is the identifier for the person sending the message or command and is present in all documents for differentiation purposes. Any assistance on this matter would be highly appreciated.
module.exports.addItem = async (userId, item) => {
profileSchema.findOne(userId, async(err, data)=> {
console.log('Data exists: ' + !!data)
if(data) {
const hasItem = Object.keys(data.items).includes(item)
console.log('Item found: ' + !!hasItem)
if(!hasItem) {
data.items[item] = 1
}
else {
data.items[item]++
}
await profileSchema.findOneAndUpdate(userId, data)
}