-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: MongoDB 3.4
-
Environment:MongoDB 3.4.14 Enterprise w/ MongoClient Node driver
-
Empty show more show less
As shown in the screenshot attached, I have a collection called Authors.
I'm accessing a collection from Node.js using the following JavaScript call.
Today, I have experienced "UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'collection' of undefined"
with the line theDB.collection(COLL_AUTHORS) once. Only once so far.
I cannot reproduce this error, but just a concern why the mongDB fails to recognize the existing collecton? What is the best way to handle this kind of random error?
```
const COLL_AUTHORS = "Authors"
let MongoClient = require('mongodb').MongoClient
let queryAuthorByUid = async (uidString) => {
console.log('queryAuthorByUidAsync : '+uidString)
const authors=theDB.collection(COLL_AUTHORS)
// find by uid
var who=awaitauthors.findOne({userid:uidString})
console.log('found author 'uidString'? = '+who)
return who
}
```