enjalot / blockbuilder

Create, fork and edit d3.js code snippets for use with bl.ocks.org right in the browser, no terminal required.
Other
323 stars 59 forks source link

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

Open micahstubbs opened 5 years ago

micahstubbs commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

let's try a

brew upgrade mongodb
micahstubbs commented 4 years ago

hi former self 👋

did you ever solve this one? 😅

micahstubbs commented 4 years ago
➜  blockbuilder git:(master) brew upgrade mongodb
Error: mongodb: unknown version :mountain_lion
micahstubbs commented 4 years ago

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 commented 4 years ago

upgrading our mongodb nodejs dependency and fixing the errors as I go:

https://www.npmjs.com/package/mongodb https://github.com/mongodb/node-mongodb-native/blob/HEAD/CHANGES_3.0.0.md https://stackoverflow.com/questions/56625122/typeerror-connect-only-accepts-a-callback

micahstubbs commented 4 years ago

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)
Saad-Abbasi commented 4 years ago

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 commented 1 year ago

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

curran commented 1 year ago

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