How can I resolve result
. Currently, my code doesn't resolve result
and console logs "Successfully found document: [Object object]". This is MongoDB. I would appretiate any help.
await dbo.collection("a").findOne({ item: "journal" }, {_id:0})
.then(result => {
async function rs() {
await result
}
rs()
if(result) {
console.log(`Successfully found document: ${result}.`);
} else {
console.log("No document matches the provided query.");
}
return result;
})
.catch(err => console.error(`Failed to find document: ${err}`));
This is my MongoDB document:
_id:61462a7bf3c0be993bcfdc3e
item:"journal"
qty:25
size:Object
status:"A"
CodePudding user response:
Try doing:
const results = await dbo.collection("a").findOne({ item: "journal" })
if(!!results) {
console.log(`Successfully found document: ${JSON.stringify(result)}.`);
}
else {
console.log("No document matches the provided query.");
}
// rest of the logic
Make sure the code above that you are executing is wrapped inside an async function.
Feel free to ask any future questions. Thanks :)