gpt4 book ai didi

node.js - Monk - 查询后数据去了哪里?

转载 作者:太空宇宙 更新时间:2023-11-04 03:19:11 24 4
gpt4 key购买 nike

我今天开始使用Monk,有一些东西我不太明白,而且文档太少了。

首先是代码:

    const movieToProcess = movieCollection.findOne({ link: videoURL }).then((doc) => {
console.log(doc)
console.log("BLABLA")
});
console.log("CURSOR", typeof(movieToProcess))

首先,我不明白为什么 Promise .then() 中的两个 console.log 没有显示,这正常吗?如果是这样,为什么?

如果 console.logs 不起作用是不正常的,这是为什么?

最后,那么如何获取findOne()的返回值呢?

奖励:除了 findOne() 之外,还有其他函数来检查数据库中是否存在该值吗?

对于这些问题,我深表歉意,但 Monk 的文档并不多。

最佳答案

一些事情:

在您的示例中,您将 movieToProcess 设置为 movieCollection.findOne() 的值,同时还对其调用 .then()

.then中,docfindOne()的返回值

此外,引用@Geert-Jan 的评论,该 promise 可能被拒绝,而您没有捕获它。

试试这个:

movieCollection.findOne({ link: videoURL })
.then((doc) => {
console.log(doc)
console.log("BLABLA")
})
.catch((err) => {
console.log(err)
})

我还要补充一点,findOne() 不返回光标,而是返回文档。

关于node.js - Monk - 查询后数据去了哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52450226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com