Adding data to the database

Inside of Atom, before our call to db.close, we're going to insert a new record into a collection. This is going to be the Todo application. We're going to have two collections in this app:

  • a Todos collection
  • a Users collection

We can go ahead and start adding some data to the Todos collection by calling db.collection. The db.collection method takes the string name for the collection you want to insert into as its only argument. Now, like the actual database itself, you don't need to create this collection first. You can simply give it a name, like Todos, and you can start inserting into it. There is no need to run any command to create it:

db.collection('Todos')

Next, we're going to use a method available in ...

Get Advanced Node.js Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.