Howtographql: Error when using mongodb 3

Created on 30 Dec 2017  路  3Comments  路  Source: howtographql/howtographql

(node:12420) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: db.collection is not a function
(node:12420) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Downloading to 2.2.33 solves the problem

Most helpful comment

Updating the mongo-connector.js to the following code fixed the problem.

const { MongoClient } = require('mongodb');

const MONGO_URL = 'mongodb://localhost:27017';

module.exports = async () => {
    const client = await MongoClient.connect(MONGO_URL);    
    const db = client.db('hackernews');
    return { Links: db.collection('links') };  
}

All 3 comments

Updating the mongo-connector.js to the following code fixed the problem.

const { MongoClient } = require('mongodb');

const MONGO_URL = 'mongodb://localhost:27017';

module.exports = async () => {
    const client = await MongoClient.connect(MONGO_URL);    
    const db = client.db('hackernews');
    return { Links: db.collection('links') };  
}

Thanks a lot for pointing that out @cmarchena 馃檹 The issue was fixed in the latest update to the Node tutorial 馃檪

Was this page helpful?
0 / 5 - 0 ratings