Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'collection' of null #243

Open
micahstubbs opened this issue Aug 27, 2019 · 10 comments · May be fixed by #250
Open

TypeError: Cannot read property 'collection' of null #243

micahstubbs opened this issue Aug 27, 2019 · 10 comments · May be fixed by #250
Assignees
Labels

Comments

@micahstubbs
Copy link
Collaborator

steps to reproduce

cd blockbuilder
yarn build
node server.js

#
# this part is expected for local build without a local ssl cert
#
error with https files Error: ENOENT: no such file or directory, open '/Users/m/workspace/blockbuilder/sslcert/privkey.pem'
    at Object.openSync (fs.js:431:3)
    at Object.readFileSync (fs.js:333:35)
    at Object.<anonymous> (/Users/m/workspace/blockbuilder/server.js:25:19)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Function.Module.runMain (internal/modules/cjs/loader.js:837:10)
    at internal/main/run_main_module.js:17:11 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/m/workspace/blockbuilder/sslcert/privkey.pem'
}
express-session deprecated undefined resave option; provide resave option server.js:108:3
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option server.js:108:3
Elasticsearch INFO: 2019-08-27T03:24:44Z
  Adding connection to http://35.226.78.72:9200/

#
# this part is the bug
#
/Users/m/workspace/blockbuilder/node_modules/mongodb/lib/mongo_client.js:421
          throw err
          ^

TypeError: Cannot read property 'collection' of null
    at /Users/m/workspace/blockbuilder/server.js:136:20
    at connectCallback (/Users/m/workspace/blockbuilder/node_modules/mongodb/lib/mongo_client.js:527:5)
    at /Users/m/workspace/blockbuilder/node_modules/mongodb/lib/mongo_client.js:418:11
    at processTicksAndRejections (internal/process/task_queues.js:82:9)
@micahstubbs micahstubbs self-assigned this Aug 27, 2019
@micahstubbs
Copy link
Collaborator Author

micahstubbs commented Aug 27, 2019

ah! I think this means that the server cannot connect to a running instance of MongoDb 💡

// server.js
MongoClient.connect(
  mongoUrl,
  function(err, db) {
    var users = db.collection('users')

@micahstubbs
Copy link
Collaborator Author

let's try a

brew upgrade mongodb

@micahstubbs
Copy link
Collaborator Author

hi former self 👋

did you ever solve this one? 😅

@micahstubbs
Copy link
Collaborator Author

➜  blockbuilder git:(master) brew upgrade mongodb
Error: mongodb: unknown version :mountain_lion

@micahstubbs
Copy link
Collaborator Author

micahstubbs commented Mar 2, 2020

https://superuser.com/questions/1478156/error-mongodb-unknown-version-mountain-lion

ah hah!

brew services stop mongodb
brew uninstall mongodb

brew tap mongodb/brew
brew install mongodb-community
brew services start mongodb-community

@micahstubbs
Copy link
Collaborator Author

@micahstubbs
Copy link
Collaborator Author

here's what I see now:

➜  blockbuilder git:(micah/243/mongodb-error) ✗ node server.js

error with https files Error: ENOENT: no such file or directory, open '/Users/m/workspace/blockbuilder/sslcert/privkey.pem'
    at Object.openSync (fs.js:457:3)
    at Object.readFileSync (fs.js:359:35)
    at Object.<anonymous> (/Users/m/workspace/blockbuilder/server.js:25:19)
    at Module._compile (internal/modules/cjs/loader.js:1144:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1164:10)
    at Module.load (internal/modules/cjs/loader.js:993:32)
    at Function.Module._load (internal/modules/cjs/loader.js:892:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/m/workspace/blockbuilder/sslcert/privkey.pem'
}
express-session deprecated undefined resave option; provide resave option server.js:108:3
express-session deprecated undefined saveUninitialized option; provide saveUninitialized option server.js:108:3
Elasticsearch INFO: 2020-03-02T08:45:02Z
  Adding connection to http://35.226.78.72:9200/

(node:5938) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
/Users/m/workspace/blockbuilder/node_modules/mongodb/lib/utils.js:720
          throw error;
          ^

TypeError: Cannot read property 'db' of undefined
    at /Users/m/workspace/blockbuilder/server.js:136:21
    at /Users/m/workspace/blockbuilder/node_modules/mongodb/lib/utils.js:717:9
    at /Users/m/workspace/blockbuilder/node_modules/mongodb/lib/mongo_client.js:222:23
    at connectCallback (/Users/m/workspace/blockbuilder/node_modules/mongodb/lib/operations/connect.js:350:5)
    at /Users/m/workspace/blockbuilder/node_modules/mongodb/lib/operations/connect.js:417:14
    at Server.<anonymous> (/Users/m/workspace/blockbuilder/node_modules/mongodb/lib/topologies/server.js:230:11)
    at Object.onceWrapper (events.js:428:26)
    at Server.emit (events.js:321:20)
    at Pool.<anonymous> (/Users/m/workspace/blockbuilder/node_modules/mongodb/lib/core/topologies/server.js:436:21)

@micahstubbs micahstubbs linked a pull request Mar 2, 2020 that will close this issue
@Saad-Abbasi
Copy link

This issue can be fixed in this way,
if you have modified your MongoDB model you need to create a new collection. because in the previous collection there is not created any new field and you may be still referencing that one.
therefore this error TypeError: Cannot read property 'collection' of null

@muhrizmrz
Copy link

Hey, how to create a new collection.I mean it is creating new collection.

@curran
Copy link
Collaborator

curran commented Dec 26, 2022

@muhrizmrz Are you trying to spin up an instance of Blockbuilder?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants