ryanthtra (5) [Avatar] Offline
FYI for those going through this lesson, you must install the NodeJS MongoDB driver v2, or else you you encounter the error:

TypeError: db.collection is not a function

because by default, you're installing MongoDB driver v3.

So in your terminal/command line you should
$ npm install mongodb@2 --save
TheWexler (62) [Avatar] Offline
Thanks for posting this. Using version 2 is a good way around the db.connection issue. The problem here is that your connection to the MongoDB server returns just that, your connection to the server. So, to get the database you want you need to:

1) Change the first line to connect to your server only (not the database directly) with

 MongoDB.connect('mongodb://localhost:27017', (error, client) => {

2) Change the `db` argument to `client`, as it represents your connection as a client
3) Add

let db = client.db('<db_name>');

Now you should able to continue using `db` as suggested in the book. These changes will be reflected in the next update. Thank you!