Nodejs operation mongodb findOne/find setting projection parameter does not work?

mongodb:3.6.5
node:9.9.0
koa:2.5.0
npm-mongodb:3.0.5

problems encountered:

query with findOne/find with projection parameters
return results in node with deleted fields

router.post("/manage", async(ctx, next) => {
    var users = db.collection("user");
    var doc = await users.findOne({userName:"yunf"},{_id:0});
    var doc1 = await users.find({userName:"yunf"},{_id:0}).toArray();
   
    console.log(doc);
    console.log(doc1 );
});
            
// 

// { 
//   _id: 5ac1cfe24a814acb143e3084,
//   userName: "yunf",
//   authority: "00000000010000",
//   cerationTime: "",
//   updateTime: 2018-04-06T06:18:55.188Z,
//   userPwd: "$2a$10$IA7/C9fplPoxY6ilTbadyeBJjAxHRUIgP.ezOQqYMCv7vHXPhx39u" 
// }...

but the same code shell returns

normally

the find () query for documents that have looked up mongodb 3.6returns the fields returned by cursors that can be specified with project

var cursor3 = db.collection("user").find({}).project({_id: 0 }).toArray();

// { userName: "yunf"}]

but why does querying with findOne/find with projection parameters not work
is a version problem? Ask the boss for advice!

Mar.01,2021

the mongodb you use is a package of nodejs, rather than a native query statement, which is the final result of package generation.
Node.js MongoDB Driver API

document clearly find (query, options) , options does not have _ id in the definition, there is projection should be what you want.

Menu