Advanced Node.js Development
上QQ阅读APP看书,第一时间看更新

Writing a query to fetch certain values

In order to query based on certain values, let's go ahead and switch up our Todos. Currently, both of them have a completed value equal to false. Let's go ahead and change the Walk the dog completed value to true so we can try to just query items that aren't completed. Over in Robomongo, I'm going to right-click the document and click Edit Document, and there we can edit the values. I'm going to change the completed value from false to true, and then I can save the record:

Inside of the Terminal, I can rerun the script to prove that it has changed. I'm going to shut down the script by running control + C, and then I can rerun it:

As shown in the preceding screenshot, we have our two Todos, one with a completed value of false and one with a completed value of true. By default, a Todo app is probably only going to show you the Todos collection you haven't completed. The ones you have completed, like Walk the dog, will probably be hidden, although they could be accessible if you clicked a button like Show all Todos. Let's go ahead and write a query that just fetches the Todos collection that have a completed status set to false.