openKB icon indicating copy to clipboard operation
openKB copied to clipboard

Using MongoDB causes Error - TypeError: db.collection is not a function

Open chambear2809 opened this issue 4 years ago • 0 comments

Hello I am attempting to set up the openKB app in my lab environment with MongoDB as my database. I can confirm when running with neDB configured it works wonderfully. However, when configured for MongoDB the app fails to start. MongoDB is running on a different server than the application.

After issuing npm start I get the following.

Console Output of npm start

cisco@php-test:~/openKB$ npm start

> [email protected] start /home/cisco/openKB
> node app.js

(node:4034703) 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.
TypeError: db.collection is not a function
    at MongoClient.connect (/home/cisco/openKB/app.js:351:23)
    at executeCallback (/home/cisco/openKB/node_modules/mongodb/lib/operations/execute_operation.js:74:5)
    at err (/home/cisco/openKB/node_modules/mongodb/lib/operations/connect.js:210:7)
    at connectCallback (/home/cisco/openKB/node_modules/mongodb/lib/operations/connect.js:375:5)
    at server.connect (/home/cisco/openKB/node_modules/mongodb/lib/operations/connect.js:468:5)
    at Server.connectHandler (/home/cisco/openKB/node_modules/mongodb/lib/topologies/server.js:291:9)
    at Object.onceWrapper (events.js:286:20)
    at Server.emit (events.js:198:13)
    at Pool.<anonymous> (/home/cisco/openKB/node_modules/mongodb/lib/core/topologies/server.js:384:12)
    at Pool.emit (events.js:198:13)
clean
/home/cisco/openKB/app.js:375
            app.db.close();
                   ^

TypeError: Cannot read property 'close' of undefined
    at exitHandler (/home/cisco/openKB/app.js:375:20)
    at process.emit (events.js:198:13)
    at process.exit (internal/process/per_thread.js:168:15)
    at exitHandler (/home/cisco/openKB/app.js:382:17)
    at process.emit (events.js:203:15)
    at process._fatalException (internal/bootstrap/node.js:497:27)
npm ERR! code ELIFECYCLE
npm ERR! errno 7
npm ERR! [email protected] start: `node app.js`
npm ERR! Exit status 7
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/cisco/.npm/_logs/2021-09-22T18_43_49_637Z-debug.log
cisco@php-test:~/openKB$

Config.json

{
    "settings": {
        "route_name": "kb",
        "num_top_results": "10",
        "date_format": "DD/MM/YYYY h:mmA",
        "show_view_count": true,
        "update_view_count_logged_in": false,
        "show_published_date": true,
        "sort_by": {
            "field": "kb_viewcount",
            "order": -1
        },
        "website_title": "openKB",
        "show_featured_articles": true,
        "show_featured_in_article": false,
        "featured_articles_count": "4",
        "password_protect": false,
        "show_kb_meta": true,
        "suggest_allowed": true,
        "show_author_email": true,
        "mermaid": false,
        "mathjax": false,
        "mathjax_input_mode": "TeX-MML-AM_CHTML",
        "app_context": "",
        "links_blank_page": true,
        "database": {
            "type": "mongodb",
            "connection_string": "mongodb://10.0.101.200:27017/openkb"
        },
        "allow_voting": true,
        "google_analytics": "",
        "theme": "",
        "show_logon": true,
        "add_header_anchors": false,
        "typeahead_search": true,
        "index_article_body": false,
        "enable_spellchecker": true,
        "show_website_logo": true,
        "website_description": "openKB is an Open Source Node.js Markdown based knowledge base/FAQ/Wiki app with powerful lunr search",
        "article_versioning": false,
        "api_auth_token": "",
        "api_allowed": false,
        "locale": "en",
        "env": "",
        "style": {
            "cssHeaderBackgroundColor": "",
            "cssHeaderTextColor": "",
            "cssFooterBackgroundColor": "",
            "cssFooterTextColor": "",
            "cssButtonBackgroundColor": "",
            "cssButtonTextColor": "",
            "cssLinkColor": "",
            "cssTextColor": "",
            "cssFontFamily": ""
        }
    }
}

Can share my app.json, but no changes were made other than adding AppDynamics APM agent.

chambear2809 avatar Sep 22 '21 18:09 chambear2809