I have started using Monk today, and there are a few things that I don't really get, and documentation is too light.
First here is the code:
const movieToProcess = movieCollection.findOne({ link: videoURL }).then((doc) => {
console.log(doc)
console.log("BLABLA")
});
console.log("CURSOR", typeof(movieToProcess))
First thing, I don't understand why the two console.log inside the promise .then() are not displaying, is that normal? If so, why?
And if this is not normal that the console.logs
don't work, why is that?
And finally, in then, how can I get the return value of findOne()
?
Bonus: Is there another function than findOne()
to check if the value exist in the database?
I apologise for these questions, but there are not that much documentation for Monk.
A few things:
In your example you are setting movieToProcess
to the value of movieCollection.findOne()
while also calling .then()
on it.
in your .then
, doc
is the return value of findOne()
ALSO, referring to @Geert-Jan's comment, the promise is probably being rejected and you aren't catching it.
Try this:
movieCollection.findOne({ link: videoURL })
.then((doc) => {
console.log(doc)
console.log("BLABLA")
})
.catch((err) => {
console.log(err)
})
I'll also add that findOne()
does not return a cursor, it returns a document.