How to do field selection on find() in the mongodb native driver?

mongodb, node.js

Solution

The field selection argument to `find` is an object, not an array. And you can't mix field inclusion and exclusion (except for `_id`), so it should be:

db.collection("test").find({}, {'name': true}).toArray(function(err, results) {
    console.dir(results);
});

Problem

I am using the mongodb native driver for node.js and can't get to work the field selection. What I want to do is to limit fields to name. I do not want the 'last' in the output. I am doing this: ``` db.collection("test").find({},[{'name':true,'last':false}]).toArray(function(err, results) { console.dir(results); }); ``` But the log prints: ``` [ { _id: 524b53588aa4f388de1c2ddb }, { _id: 524b53548aa4f388de1c2dda } ] ``` So there is no `name` in the output. Update: I have tried an object instead of array -- did not work. The reason is really mixing inclusion and exclusion. You can't mix it. When I only had `"name":true` it worked.

Original source