We have not yet performed any truly interesting queries against our collection. Up until now, all we did was to retrieve all documents contained in our collection by performing collection.find() without any filter. More complex filters are available of course.
Let's rewrite the existing code in order to retrieve only specific documents in our doFind function. First, a very simple example – we are going to retrieve all documents where the v attribute has a value of 5. Let's change the following line:
collection.find().toArray(function (err, documents) {
The preceding line is changed to:
collection.find({'v': 5}).toArray(function (err, documents) {
The preceding changes result in only the matching documents being printed:
Inserted 20 documents: [ { id: 53d7698d99c6107303ad204c, n: '#8', v: 5 }, { id: 53d7698d99c6107303ad2050, n: &apos...