Mongodb Get Entire Document From A Value
i want to get all values of a mongodb document from a single value. Example: 'id': 'id', 'name': 'name', 'description': 'description', 'invite': 'invite', 'supp
Solution 1:
When you call bots.findOne({data})
it returns a "Promise", not the data. You need to wait for the Promise resolve to get the data. You can try this code.
socket.on("bot_req_id", asyncfunction(data) {
let db = mongoose.db("wumpusCave")
let bots = db.collection("bots")
console.log(data)
let bot = await bots.findOne({data})
console.log(bot);
socket.emit("bot_res_id", bot)
})
This article may help you understand the concept: https://scotch.io/courses/10-need-to-know-javascript-concepts/callbacks-promises-and-async
Post a Comment for "Mongodb Get Entire Document From A Value"