Implementing the count method

Now, we're going to go ahead and implement count over inside of Atom. What I'm going to do is take the current query, copy it to the clipboard, and then comment it out. I'm going to go ahead and replace our call to toArray with a call to count. Let's go ahead and remove the query that we pass in to find. What we're going to do here is count up all of the Todos in the Todos collection. Instead of having a call to toArray, we're going to have a call to count instead.

db.collection('Todos').find({}).count().then((count) => {

As you saw inside of the examples for count, they call count like this: calling count, passing in a callback function that gets called with an error, or the actual count. You can also have a ...

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.