demo_mongodb_find_fields_error.js:
var MongoClient = require('mongodb').MongoClient; var url = "mongodb://localhost:27017/mydb"; MongoClient.connect(url, function(err, db) { if (err) throw err; //Exclude "address" field in the result: db.collection("customers").find({}, { projection: { name: 1, address: 0 } }).toArray(function(err, result) { if (err) throw err; console.log(result); db.close(); }); });
C:\Users\My Name>node demo_mongodb_find_fields_error.js
C:\Users\Your Name\node_modules\mongodb\lib\utils.js98
process.nextTick(function() { throw err; });
^
MongoError: Projection cannot have a mix of inclusion and exclusion.
...