Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1469

UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'collection' of undefined

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: MongoDB 3.4
    • Labels:
    • Environment:
      MongoDB 3.4.14 Enterprise w/ MongoClient Node driver

      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
      }
      ```

            Assignee:
            Unassigned Unassigned
            Reporter:
            daocircle@gmail.com Dao Circle
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: