在尝试使 findone() 工作近 2 天后,我终于做到了。但我现在面临的问题是它不返回“正常”对象 ID。相反,它返回一堆奇怪的数字。
我的问题是,如何返回正常的对象 ID(如图所示)?
以下是我的代码、控制台中的响应以及我的 robo 3t 的屏幕截图:-
router.post("/api/find", async (ctx: RouterContext) => {
try {
const findUser = await usersCollection.findOne({
email: "h@y.c"
// @ts-ignore
}, { noCursorTimeout: false });
console.log(findUser);
ctx.response.body = { message: "Found!" };
ctx.response.status = 200;
} catch (error) {
console.log(error);
}
});
控制台输出:
<块引用>{
_id: ObjectId2 {
[Symbol(id)]: Buffer2(12) [
96, 130, 242, 52, 146,
89, 220, 104, 191, 143,
75, 44
]
},
username: "user1",
password: "pass1",
email: "h@y.c"
}